From add5d32f9b0cb3cda15624fb7aef3998096ff3f6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 21 Feb 2010 12:59:41 -0800 Subject: Moved lib and include contents of dboard and mboard one directory up and prefixed them with dboard_ and mboard_. And yes, the code is compiling. --- host/lib/usrp/dboard/base.cpp | 117 ---------- host/lib/usrp/dboard/basic.cpp | 4 +- host/lib/usrp/dboard/dboards.hpp | 16 +- host/lib/usrp/dboard/id.cpp | 34 --- host/lib/usrp/dboard/interface.cpp | 54 ----- host/lib/usrp/dboard/manager.cpp | 231 ------------------- host/lib/usrp/dboard_base.cpp | 117 ++++++++++ host/lib/usrp/dboard_id.cpp | 34 +++ host/lib/usrp/dboard_interface.cpp | 54 +++++ host/lib/usrp/dboard_manager.cpp | 231 +++++++++++++++++++ host/lib/usrp/mboard/base.cpp | 29 --- host/lib/usrp/mboard/usrp2.cpp | 116 ---------- host/lib/usrp/mboard/usrp2/dboard_impl.cpp | 123 ---------- host/lib/usrp/mboard/usrp2/dboard_interface.cpp | 284 ----------------------- host/lib/usrp/mboard/usrp2/dboard_interface.hpp | 63 ----- host/lib/usrp/mboard/usrp2/dsp_impl.cpp | 293 ------------------------ host/lib/usrp/mboard/usrp2/fw_common.h | 190 --------------- host/lib/usrp/mboard/usrp2/mboard_impl.cpp | 196 ---------------- host/lib/usrp/mboard/usrp2/usrp2_impl.cpp | 103 --------- host/lib/usrp/mboard/usrp2/usrp2_impl.hpp | 160 ------------- host/lib/usrp/mboard_base.cpp | 29 +++ host/lib/usrp/usrp.cpp | 4 +- host/lib/usrp/usrp2.cpp | 116 ++++++++++ host/lib/usrp/usrp2/dboard_impl.cpp | 123 ++++++++++ host/lib/usrp/usrp2/dboard_interface.cpp | 284 +++++++++++++++++++++++ host/lib/usrp/usrp2/dboard_interface.hpp | 63 +++++ host/lib/usrp/usrp2/dsp_impl.cpp | 293 ++++++++++++++++++++++++ host/lib/usrp/usrp2/fw_common.h | 190 +++++++++++++++ host/lib/usrp/usrp2/mboard_impl.cpp | 196 ++++++++++++++++ host/lib/usrp/usrp2/usrp2_impl.cpp | 102 +++++++++ host/lib/usrp/usrp2/usrp2_impl.hpp | 160 +++++++++++++ 31 files changed, 2004 insertions(+), 2005 deletions(-) delete mode 100644 host/lib/usrp/dboard/base.cpp delete mode 100644 host/lib/usrp/dboard/id.cpp delete mode 100644 host/lib/usrp/dboard/interface.cpp delete mode 100644 host/lib/usrp/dboard/manager.cpp create mode 100644 host/lib/usrp/dboard_base.cpp create mode 100644 host/lib/usrp/dboard_id.cpp create mode 100644 host/lib/usrp/dboard_interface.cpp create mode 100644 host/lib/usrp/dboard_manager.cpp delete mode 100644 host/lib/usrp/mboard/base.cpp delete mode 100644 host/lib/usrp/mboard/usrp2.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/dboard_impl.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/dboard_interface.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/dboard_interface.hpp delete mode 100644 host/lib/usrp/mboard/usrp2/dsp_impl.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/fw_common.h delete mode 100644 host/lib/usrp/mboard/usrp2/mboard_impl.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/usrp2_impl.cpp delete mode 100644 host/lib/usrp/mboard/usrp2/usrp2_impl.hpp create mode 100644 host/lib/usrp/mboard_base.cpp create mode 100644 host/lib/usrp/usrp2.cpp create mode 100644 host/lib/usrp/usrp2/dboard_impl.cpp create mode 100644 host/lib/usrp/usrp2/dboard_interface.cpp create mode 100644 host/lib/usrp/usrp2/dboard_interface.hpp create mode 100644 host/lib/usrp/usrp2/dsp_impl.cpp create mode 100644 host/lib/usrp/usrp2/fw_common.h create mode 100644 host/lib/usrp/usrp2/mboard_impl.cpp create mode 100644 host/lib/usrp/usrp2/usrp2_impl.cpp create mode 100644 host/lib/usrp/usrp2/usrp2_impl.hpp (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/dboard/base.cpp b/host/lib/usrp/dboard/base.cpp deleted file mode 100644 index 92a886407..000000000 --- a/host/lib/usrp/dboard/base.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// -// 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 . -// - -#include -#include -#include - -using namespace uhd::usrp::dboard; - -/*********************************************************************** - * base dboard base class - **********************************************************************/ -base::base(ctor_args_t const& args){ - boost::tie(_subdev_name, _dboard_interface, _rx_id, _tx_id) = args; -} - -base::~base(void){ - /* NOP */ -} - -std::string base::get_subdev_name(void){ - return _subdev_name; -} - -interface::sptr base::get_interface(void){ - return _dboard_interface; -} - -dboard_id_t base::get_rx_id(void){ - return _rx_id; -} - -dboard_id_t base::get_tx_id(void){ - return _tx_id; -} - -/*********************************************************************** - * xcvr dboard base class - **********************************************************************/ -xcvr_base::xcvr_base(ctor_args_t const& args) : base(args){ - if (get_rx_id() == ID_NONE){ - throw std::runtime_error(str(boost::format( - "cannot create xcvr board when the rx id is \"%s\"" - ) % id::to_string(ID_NONE))); - } - if (get_tx_id() == ID_NONE){ - throw std::runtime_error(str(boost::format( - "cannot create xcvr board when the tx id is \"%s\"" - ) % id::to_string(ID_NONE))); - } -} - -xcvr_base::~xcvr_base(void){ - /* NOP */ -} - -/*********************************************************************** - * rx dboard base class - **********************************************************************/ -rx_base::rx_base(ctor_args_t const& args) : base(args){ - if (get_tx_id() != ID_NONE){ - throw std::runtime_error(str(boost::format( - "cannot create rx board when the tx id is \"%s\"" - " -> expected a tx id of \"%s\"" - ) % id::to_string(get_tx_id()) % id::to_string(ID_NONE))); - } -} - -rx_base::~rx_base(void){ - /* NOP */ -} - -void rx_base::tx_get(const wax::obj &, wax::obj &){ - throw std::runtime_error("cannot call tx_get on a rx dboard"); -} - -void rx_base::tx_set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("cannot call tx_set on a rx dboard"); -} - -/*********************************************************************** - * tx dboard base class - **********************************************************************/ -tx_base::tx_base(ctor_args_t const& args) : base(args){ - if (get_rx_id() != ID_NONE){ - throw std::runtime_error(str(boost::format( - "cannot create tx board when the rx id is \"%s\"" - " -> expected a rx id of \"%s\"" - ) % id::to_string(get_rx_id()) % id::to_string(ID_NONE))); - } -} - -tx_base::~tx_base(void){ - /* NOP */ -} - -void tx_base::rx_get(const wax::obj &, wax::obj &){ - throw std::runtime_error("cannot call rx_get on a tx dboard"); -} - -void tx_base::rx_set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("cannot call rx_set on a tx dboard"); -} diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp index 35512aa5f..f39ebff2f 100644 --- a/host/lib/usrp/dboard/basic.cpp +++ b/host/lib/usrp/dboard/basic.cpp @@ -20,7 +20,7 @@ /*********************************************************************** * Basic RX dboard **********************************************************************/ -basic_rx::basic_rx(ctor_args_t const& args) : rx_base(args){ +basic_rx::basic_rx(ctor_args_t const& args) : rx_dboard_base(args){ /* NOP */ } @@ -39,7 +39,7 @@ void basic_rx::rx_set(const wax::obj &, const wax::obj &){ /*********************************************************************** * Basic TX dboard **********************************************************************/ -basic_tx::basic_tx(ctor_args_t const& args) : tx_base(args){ +basic_tx::basic_tx(ctor_args_t const& args) : tx_dboard_base(args){ /* NOP */ } diff --git a/host/lib/usrp/dboard/dboards.hpp b/host/lib/usrp/dboard/dboards.hpp index 0e740856f..79b90d593 100644 --- a/host/lib/usrp/dboard/dboards.hpp +++ b/host/lib/usrp/dboard/dboards.hpp @@ -18,17 +18,17 @@ #ifndef INCLUDED_LOCAL_DBOARDS_HPP #define INCLUDED_LOCAL_DBOARDS_HPP -#include +#include -using namespace uhd::usrp::dboard; +using namespace uhd::usrp; /*********************************************************************** * The basic boards: **********************************************************************/ -class basic_rx : public rx_base{ +class basic_rx : public rx_dboard_base{ public: - static base::sptr make(ctor_args_t const& args){ - return base::sptr(new basic_rx(args)); + static dboard_base::sptr make(ctor_args_t const& args){ + return dboard_base::sptr(new basic_rx(args)); } basic_rx(ctor_args_t const& args); ~basic_rx(void); @@ -37,10 +37,10 @@ public: void rx_set(const wax::obj &key, const wax::obj &val); }; -class basic_tx : public tx_base{ +class basic_tx : public tx_dboard_base{ public: - static base::sptr make(ctor_args_t const& args){ - return base::sptr(new basic_tx(args)); + static dboard_base::sptr make(ctor_args_t const& args){ + return dboard_base::sptr(new basic_tx(args)); } basic_tx(ctor_args_t const& args); ~basic_tx(void); diff --git a/host/lib/usrp/dboard/id.cpp b/host/lib/usrp/dboard/id.cpp deleted file mode 100644 index b62e469de..000000000 --- a/host/lib/usrp/dboard/id.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// 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 . -// - -#include -#include -#include - -using namespace uhd::usrp::dboard; - -std::string id::to_string(const dboard_id_t &id){ - //map the dboard ids to string representations - uhd::dict id_to_str; - id_to_str[ID_NONE] = "none"; - id_to_str[ID_BASIC_TX] = "basic tx"; - id_to_str[ID_BASIC_RX] = "basic rx"; - - //get the string representation - std::string name = (id_to_str.has_key(id))? id_to_str[id] : "unknown"; - return str(boost::format("%s (0x%.4x)") % name % id); -} diff --git a/host/lib/usrp/dboard/interface.cpp b/host/lib/usrp/dboard/interface.cpp deleted file mode 100644 index b8f6724ba..000000000 --- a/host/lib/usrp/dboard/interface.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// 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 . -// - -#include - -using namespace uhd::usrp::dboard; - -interface::interface(void){ - /* NOP */ -} - -interface::~interface(void){ - /* NOP */ -} - -void interface::write_spi( - spi_dev_t dev, - spi_push_t push, - const byte_vector_t &buf -){ - transact_spi(dev, SPI_LATCH_RISE, push, buf, false); //dont readback -} - -interface::byte_vector_t interface::read_spi( - spi_dev_t dev, - spi_latch_t latch, - size_t num_bytes -){ - byte_vector_t buf(num_bytes, 0x00); //dummy data - return transact_spi(dev, latch, SPI_PUSH_RISE, buf, true); //readback -} - -interface::byte_vector_t interface::read_write_spi( - spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, - const byte_vector_t &buf -){ - return transact_spi(dev, latch, push, buf, true); //readback -} diff --git a/host/lib/usrp/dboard/manager.cpp b/host/lib/usrp/dboard/manager.cpp deleted file mode 100644 index 337c31ad6..000000000 --- a/host/lib/usrp/dboard/manager.cpp +++ /dev/null @@ -1,231 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include -#include "dboards.hpp" - -using namespace uhd; -using namespace uhd::usrp::dboard; -using namespace boost::assign; - -/*********************************************************************** - * register internal dboards - * - * Register internal/known dboards located in this build tree. - * Each board should have entries below mapping an id to a constructor. - * The xcvr type boards should register both rx and tx sides. - * - * This function will be called before new boards are registered. - * This allows for internal boards to be externally overridden. - * This function will also be called when creating a new manager - * to ensure that the maps are filled with the entries below. - **********************************************************************/ -static void register_internal_dboards(void){ - //ensure that this function can only be called once per instance - static bool called = false; - if (called) return; called = true; - //register the known dboards (dboard id, constructor, subdev names) - manager::register_subdevs(ID_BASIC_TX, &basic_tx::make, list_of("")); - manager::register_subdevs(ID_BASIC_RX, &basic_rx::make, list_of("a")("b")("ab")); -} - -/*********************************************************************** - * storage and registering for dboards - **********************************************************************/ -typedef boost::tuple args_t; - -//map a dboard id to a dboard constructor -static uhd::dict id_to_args_map; - -void manager::register_subdevs( - dboard_id_t dboard_id, - dboard_ctor_t dboard_ctor, - const prop_names_t &subdev_names -){ - register_internal_dboards(); //always call first - id_to_args_map[dboard_id] = args_t(dboard_ctor, subdev_names); -} - -/*********************************************************************** - * internal helper classes - **********************************************************************/ -/*! - * A special wax proxy object that forwards calls to a subdev. - * A sptr to an instance will be used in the properties structure. - */ -class subdev_proxy : boost::noncopyable, public wax::obj{ -public: - typedef boost::shared_ptr sptr; - enum type_t{RX_TYPE, TX_TYPE}; - - //structors - subdev_proxy(base::sptr subdev, type_t type) - : _subdev(subdev), _type(type){ - /* NOP */ - } - - ~subdev_proxy(void){ - /* NOP */ - } - -private: - base::sptr _subdev; - type_t _type; - - //forward the get calls to the rx or tx - void get(const wax::obj &key, wax::obj &val){ - switch(_type){ - case RX_TYPE: return _subdev->rx_get(key, val); - case TX_TYPE: return _subdev->tx_get(key, val); - } - } - - //forward the set calls to the rx or tx - void set(const wax::obj &key, const wax::obj &val){ - switch(_type){ - case RX_TYPE: return _subdev->rx_set(key, val); - case TX_TYPE: return _subdev->tx_set(key, val); - } - } -}; - -/*********************************************************************** - * dboard manager methods - **********************************************************************/ -static args_t get_dboard_args( - dboard_id_t dboard_id, - std::string const& xx_type -){ - //special case, its rx and the none id (0xffff) - if (xx_type == "rx" and dboard_id == ID_NONE){ - return args_t(&basic_rx::make, list_of("ab")); - } - - //special case, its tx and the none id (0xffff) - if (xx_type == "tx" and dboard_id == ID_NONE){ - return args_t(&basic_tx::make, list_of("")); - } - - //verify that there is a registered constructor for this id - if (not id_to_args_map.has_key(dboard_id)){ - throw std::runtime_error(str( - boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id - )); - } - - //return the dboard args for this id - return id_to_args_map[dboard_id]; -} - -manager::manager( - dboard_id_t rx_dboard_id, - dboard_id_t tx_dboard_id, - interface::sptr dboard_interface -){ - register_internal_dboards(); //always call first - - dboard_ctor_t rx_dboard_ctor; prop_names_t rx_subdevs; - boost::tie(rx_dboard_ctor, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx"); - - dboard_ctor_t tx_dboard_ctor; prop_names_t tx_subdevs; - boost::tie(tx_dboard_ctor, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx"); - - //initialize the gpio pins before creating subdevs - dboard_interface->set_gpio_ddr(interface::GPIO_RX_BANK, 0x0000, 0xffff); //all inputs - dboard_interface->set_gpio_ddr(interface::GPIO_TX_BANK, 0x0000, 0xffff); - - dboard_interface->write_gpio(interface::GPIO_RX_BANK, 0x0000, 0xffff); //all zeros - dboard_interface->write_gpio(interface::GPIO_TX_BANK, 0x0000, 0xffff); - - dboard_interface->set_atr_reg(interface::GPIO_RX_BANK, 0x0000, 0x0000, 0x0000); //software controlled - dboard_interface->set_atr_reg(interface::GPIO_TX_BANK, 0x0000, 0x0000, 0x0000); - - //make xcvr subdevs (make one subdev for both rx and tx dboards) - if (rx_dboard_ctor == tx_dboard_ctor){ - ASSERT_THROW(rx_subdevs == tx_subdevs); - BOOST_FOREACH(std::string name, rx_subdevs){ - base::sptr xcvr_dboard = rx_dboard_ctor( - base::ctor_args_t(name, dboard_interface, rx_dboard_id, tx_dboard_id) - ); - //create a rx proxy for this xcvr board - _rx_dboards[name] = subdev_proxy::sptr( - new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE) - ); - //create a tx proxy for this xcvr board - _tx_dboards[name] = subdev_proxy::sptr( - new subdev_proxy(xcvr_dboard, subdev_proxy::TX_TYPE) - ); - } - } - - //make tx and rx subdevs (separate subdevs for rx and tx dboards) - else{ - //make the rx subdevs - BOOST_FOREACH(std::string name, rx_subdevs){ - base::sptr rx_dboard = rx_dboard_ctor( - base::ctor_args_t(name, dboard_interface, rx_dboard_id, ID_NONE) - ); - //create a rx proxy for this rx board - _rx_dboards[name] = subdev_proxy::sptr( - new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE) - ); - } - //make the tx subdevs - BOOST_FOREACH(std::string name, tx_subdevs){ - base::sptr tx_dboard = tx_dboard_ctor( - base::ctor_args_t(name, dboard_interface, ID_NONE, tx_dboard_id) - ); - //create a tx proxy for this tx board - _tx_dboards[name] = subdev_proxy::sptr( - new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE) - ); - } - } -} - -manager::~manager(void){ - /* NOP */ -} - -prop_names_t manager::get_rx_subdev_names(void){ - return _rx_dboards.get_keys(); -} - -prop_names_t manager::get_tx_subdev_names(void){ - return _tx_dboards.get_keys(); -} - -wax::obj manager::get_rx_subdev(const std::string &subdev_name){ - if (not _rx_dboards.has_key(subdev_name)) throw std::invalid_argument( - str(boost::format("Unknown rx subdev name %s") % subdev_name) - ); - //get a link to the rx subdev proxy - return wax::cast(_rx_dboards[subdev_name])->get_link(); -} - -wax::obj manager::get_tx_subdev(const std::string &subdev_name){ - if (not _tx_dboards.has_key(subdev_name)) throw std::invalid_argument( - str(boost::format("Unknown tx subdev name %s") % subdev_name) - ); - //get a link to the tx subdev proxy - return wax::cast(_tx_dboards[subdev_name])->get_link(); -} diff --git a/host/lib/usrp/dboard_base.cpp b/host/lib/usrp/dboard_base.cpp new file mode 100644 index 000000000..6dd41cfd8 --- /dev/null +++ b/host/lib/usrp/dboard_base.cpp @@ -0,0 +1,117 @@ +// +// 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 . +// + +#include +#include +#include + +using namespace uhd::usrp; + +/*********************************************************************** + * dboard_base dboard dboard_base class + **********************************************************************/ +dboard_base::dboard_base(ctor_args_t const& args){ + boost::tie(_subdev_name, _dboard_interface, _rx_id, _tx_id) = args; +} + +dboard_base::~dboard_base(void){ + /* NOP */ +} + +std::string dboard_base::get_subdev_name(void){ + return _subdev_name; +} + +dboard_interface::sptr dboard_base::get_interface(void){ + return _dboard_interface; +} + +dboard_id_t dboard_base::get_rx_id(void){ + return _rx_id; +} + +dboard_id_t dboard_base::get_tx_id(void){ + return _tx_id; +} + +/*********************************************************************** + * xcvr dboard dboard_base class + **********************************************************************/ +xcvr_dboard_base::xcvr_dboard_base(ctor_args_t const& args) : dboard_base(args){ + if (get_rx_id() == ID_NONE){ + throw std::runtime_error(str(boost::format( + "cannot create xcvr board when the rx id is \"%s\"" + ) % dboard_id::to_string(ID_NONE))); + } + if (get_tx_id() == ID_NONE){ + throw std::runtime_error(str(boost::format( + "cannot create xcvr board when the tx id is \"%s\"" + ) % dboard_id::to_string(ID_NONE))); + } +} + +xcvr_dboard_base::~xcvr_dboard_base(void){ + /* NOP */ +} + +/*********************************************************************** + * rx dboard dboard_base class + **********************************************************************/ +rx_dboard_base::rx_dboard_base(ctor_args_t const& args) : dboard_base(args){ + if (get_tx_id() != ID_NONE){ + throw std::runtime_error(str(boost::format( + "cannot create rx board when the tx id is \"%s\"" + " -> expected a tx id of \"%s\"" + ) % dboard_id::to_string(get_tx_id()) % dboard_id::to_string(ID_NONE))); + } +} + +rx_dboard_base::~rx_dboard_base(void){ + /* NOP */ +} + +void rx_dboard_base::tx_get(const wax::obj &, wax::obj &){ + throw std::runtime_error("cannot call tx_get on a rx dboard"); +} + +void rx_dboard_base::tx_set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("cannot call tx_set on a rx dboard"); +} + +/*********************************************************************** + * tx dboard dboard_base class + **********************************************************************/ +tx_dboard_base::tx_dboard_base(ctor_args_t const& args) : dboard_base(args){ + if (get_rx_id() != ID_NONE){ + throw std::runtime_error(str(boost::format( + "cannot create tx board when the rx id is \"%s\"" + " -> expected a rx id of \"%s\"" + ) % dboard_id::to_string(get_rx_id()) % dboard_id::to_string(ID_NONE))); + } +} + +tx_dboard_base::~tx_dboard_base(void){ + /* NOP */ +} + +void tx_dboard_base::rx_get(const wax::obj &, wax::obj &){ + throw std::runtime_error("cannot call rx_get on a tx dboard"); +} + +void tx_dboard_base::rx_set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("cannot call rx_set on a tx dboard"); +} diff --git a/host/lib/usrp/dboard_id.cpp b/host/lib/usrp/dboard_id.cpp new file mode 100644 index 000000000..d2ef7cd7d --- /dev/null +++ b/host/lib/usrp/dboard_id.cpp @@ -0,0 +1,34 @@ +// +// 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 . +// + +#include +#include +#include + +using namespace uhd::usrp; + +std::string dboard_id::to_string(const dboard_id_t &id){ + //map the dboard ids to string representations + uhd::dict id_to_str; + id_to_str[ID_NONE] = "none"; + id_to_str[ID_BASIC_TX] = "basic tx"; + id_to_str[ID_BASIC_RX] = "basic rx"; + + //get the string representation + std::string name = (id_to_str.has_key(id))? id_to_str[id] : "unknown"; + return str(boost::format("%s (0x%.4x)") % name % id); +} diff --git a/host/lib/usrp/dboard_interface.cpp b/host/lib/usrp/dboard_interface.cpp new file mode 100644 index 000000000..f6d6b6456 --- /dev/null +++ b/host/lib/usrp/dboard_interface.cpp @@ -0,0 +1,54 @@ +// +// 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 . +// + +#include + +using namespace uhd::usrp; + +dboard_interface::dboard_interface(void){ + /* NOP */ +} + +dboard_interface::~dboard_interface(void){ + /* NOP */ +} + +void dboard_interface::write_spi( + spi_dev_t dev, + spi_push_t push, + const byte_vector_t &buf +){ + transact_spi(dev, SPI_LATCH_RISE, push, buf, false); //dont readback +} + +dboard_interface::byte_vector_t dboard_interface::read_spi( + spi_dev_t dev, + spi_latch_t latch, + size_t num_bytes +){ + byte_vector_t buf(num_bytes, 0x00); //dummy data + return transact_spi(dev, latch, SPI_PUSH_RISE, buf, true); //readback +} + +dboard_interface::byte_vector_t dboard_interface::read_write_spi( + spi_dev_t dev, + spi_latch_t latch, + spi_push_t push, + const byte_vector_t &buf +){ + return transact_spi(dev, latch, push, buf, true); //readback +} diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp new file mode 100644 index 000000000..4d52f82e8 --- /dev/null +++ b/host/lib/usrp/dboard_manager.cpp @@ -0,0 +1,231 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include +#include "dboard/dboards.hpp" + +using namespace uhd; +using namespace uhd::usrp; +using namespace boost::assign; + +/*********************************************************************** + * register internal dboards + * + * Register internal/known dboards located in this build tree. + * Each board should have entries below mapping an id to a constructor. + * The xcvr type boards should register both rx and tx sides. + * + * This function will be called before new boards are registered. + * This allows for internal boards to be externally overridden. + * This function will also be called when creating a new dboard_manager + * to ensure that the maps are filled with the entries below. + **********************************************************************/ +static void register_internal_dboards(void){ + //ensure that this function can only be called once per instance + static bool called = false; + if (called) return; called = true; + //register the known dboards (dboard id, constructor, subdev names) + dboard_manager::register_subdevs(ID_BASIC_TX, &basic_tx::make, list_of("")); + dboard_manager::register_subdevs(ID_BASIC_RX, &basic_rx::make, list_of("a")("b")("ab")); +} + +/*********************************************************************** + * storage and registering for dboards + **********************************************************************/ +typedef boost::tuple args_t; + +//map a dboard id to a dboard constructor +static uhd::dict id_to_args_map; + +void dboard_manager::register_subdevs( + dboard_id_t dboard_id, + dboard_ctor_t dboard_ctor, + const prop_names_t &subdev_names +){ + register_internal_dboards(); //always call first + id_to_args_map[dboard_id] = args_t(dboard_ctor, subdev_names); +} + +/*********************************************************************** + * internal helper classes + **********************************************************************/ +/*! + * A special wax proxy object that forwards calls to a subdev. + * A sptr to an instance will be used in the properties structure. + */ +class subdev_proxy : boost::noncopyable, public wax::obj{ +public: + typedef boost::shared_ptr sptr; + enum type_t{RX_TYPE, TX_TYPE}; + + //structors + subdev_proxy(dboard_base::sptr subdev, type_t type) + : _subdev(subdev), _type(type){ + /* NOP */ + } + + ~subdev_proxy(void){ + /* NOP */ + } + +private: + dboard_base::sptr _subdev; + type_t _type; + + //forward the get calls to the rx or tx + void get(const wax::obj &key, wax::obj &val){ + switch(_type){ + case RX_TYPE: return _subdev->rx_get(key, val); + case TX_TYPE: return _subdev->tx_get(key, val); + } + } + + //forward the set calls to the rx or tx + void set(const wax::obj &key, const wax::obj &val){ + switch(_type){ + case RX_TYPE: return _subdev->rx_set(key, val); + case TX_TYPE: return _subdev->tx_set(key, val); + } + } +}; + +/*********************************************************************** + * dboard dboard_manager methods + **********************************************************************/ +static args_t get_dboard_args( + dboard_id_t dboard_id, + std::string const& xx_type +){ + //special case, its rx and the none id (0xffff) + if (xx_type == "rx" and dboard_id == ID_NONE){ + return args_t(&basic_rx::make, list_of("ab")); + } + + //special case, its tx and the none id (0xffff) + if (xx_type == "tx" and dboard_id == ID_NONE){ + return args_t(&basic_tx::make, list_of("")); + } + + //verify that there is a registered constructor for this id + if (not id_to_args_map.has_key(dboard_id)){ + throw std::runtime_error(str( + boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id + )); + } + + //return the dboard args for this id + return id_to_args_map[dboard_id]; +} + +dboard_manager::dboard_manager( + dboard_id_t rx_dboard_id, + dboard_id_t tx_dboard_id, + dboard_interface::sptr interface +){ + register_internal_dboards(); //always call first + + dboard_ctor_t rx_dboard_ctor; prop_names_t rx_subdevs; + boost::tie(rx_dboard_ctor, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx"); + + dboard_ctor_t tx_dboard_ctor; prop_names_t tx_subdevs; + boost::tie(tx_dboard_ctor, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx"); + + //initialize the gpio pins before creating subdevs + interface->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000, 0xffff); //all inputs + interface->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000, 0xffff); + + interface->write_gpio(dboard_interface::GPIO_RX_BANK, 0x0000, 0xffff); //all zeros + interface->write_gpio(dboard_interface::GPIO_TX_BANK, 0x0000, 0xffff); + + interface->set_atr_reg(dboard_interface::GPIO_RX_BANK, 0x0000, 0x0000, 0x0000); //software controlled + interface->set_atr_reg(dboard_interface::GPIO_TX_BANK, 0x0000, 0x0000, 0x0000); + + //make xcvr subdevs (make one subdev for both rx and tx dboards) + if (rx_dboard_ctor == tx_dboard_ctor){ + ASSERT_THROW(rx_subdevs == tx_subdevs); + BOOST_FOREACH(std::string name, rx_subdevs){ + dboard_base::sptr xcvr_dboard = rx_dboard_ctor( + dboard_base::ctor_args_t(name, interface, rx_dboard_id, tx_dboard_id) + ); + //create a rx proxy for this xcvr board + _rx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE) + ); + //create a tx proxy for this xcvr board + _tx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(xcvr_dboard, subdev_proxy::TX_TYPE) + ); + } + } + + //make tx and rx subdevs (separate subdevs for rx and tx dboards) + else{ + //make the rx subdevs + BOOST_FOREACH(std::string name, rx_subdevs){ + dboard_base::sptr rx_dboard = rx_dboard_ctor( + dboard_base::ctor_args_t(name, interface, rx_dboard_id, ID_NONE) + ); + //create a rx proxy for this rx board + _rx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE) + ); + } + //make the tx subdevs + BOOST_FOREACH(std::string name, tx_subdevs){ + dboard_base::sptr tx_dboard = tx_dboard_ctor( + dboard_base::ctor_args_t(name, interface, ID_NONE, tx_dboard_id) + ); + //create a tx proxy for this tx board + _tx_dboards[name] = subdev_proxy::sptr( + new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE) + ); + } + } +} + +dboard_manager::~dboard_manager(void){ + /* NOP */ +} + +prop_names_t dboard_manager::get_rx_subdev_names(void){ + return _rx_dboards.get_keys(); +} + +prop_names_t dboard_manager::get_tx_subdev_names(void){ + return _tx_dboards.get_keys(); +} + +wax::obj dboard_manager::get_rx_subdev(const std::string &subdev_name){ + if (not _rx_dboards.has_key(subdev_name)) throw std::invalid_argument( + str(boost::format("Unknown rx subdev name %s") % subdev_name) + ); + //get a link to the rx subdev proxy + return wax::cast(_rx_dboards[subdev_name])->get_link(); +} + +wax::obj dboard_manager::get_tx_subdev(const std::string &subdev_name){ + if (not _tx_dboards.has_key(subdev_name)) throw std::invalid_argument( + str(boost::format("Unknown tx subdev name %s") % subdev_name) + ); + //get a link to the tx subdev proxy + return wax::cast(_tx_dboards[subdev_name])->get_link(); +} diff --git a/host/lib/usrp/mboard/base.cpp b/host/lib/usrp/mboard/base.cpp deleted file mode 100644 index f4f0324f3..000000000 --- a/host/lib/usrp/mboard/base.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// 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 . -// - -#include -#include - -using namespace uhd::usrp::mboard; - -base::base(void){ - /* NOP */ -} - -base::~base(void){ - /* NOP */ -} diff --git a/host/lib/usrp/mboard/usrp2.cpp b/host/lib/usrp/mboard/usrp2.cpp deleted file mode 100644 index f79ae851b..000000000 --- a/host/lib/usrp/mboard/usrp2.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include -#include -#include "usrp2/usrp2_impl.hpp" - -using namespace uhd::usrp::mboard; - -/*********************************************************************** - * Discovery over the udp transport - **********************************************************************/ -uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ - device_addrs_t usrp2_addrs; - - //create a udp transport to communicate - //TODO if an addr is not provided, search all interfaces? - std::string ctrl_port = boost::lexical_cast(USRP2_UDP_CTRL_PORT); - uhd::transport::udp udp_transport(hint["addr"], ctrl_port, true); - - //send a hello control packet - usrp2_ctrl_data_t ctrl_data_out; - ctrl_data_out.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO); - udp_transport.send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); - - //loop and recieve until the time is up - size_t num_timeouts = 0; - while(true){ - uhd::shared_iovec iov = udp_transport.recv(); - //std::cout << boost::asio::buffer_size(buff) << "\n"; - if (iov.len < sizeof(usrp2_ctrl_data_t)){ - //sleep a little so we dont burn cpu - if (num_timeouts++ > 50) break; - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - }else{ - //handle the received data - const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast(iov.base); - switch(ntohl(ctrl_data_in->id)){ - case USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE: - //make a boost asio ipv4 with the raw addr in host byte order - boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); - device_addr_t new_addr; - new_addr["name"] = "USRP2"; - new_addr["type"] = "udp"; - new_addr["addr"] = ip_addr.to_string(); - usrp2_addrs.push_back(new_addr); - break; - } - } - } - - return usrp2_addrs; -} - -/*********************************************************************** - * Structors - **********************************************************************/ -usrp2::usrp2(const device_addr_t &device_addr){ - //create a control transport - uhd::transport::udp::sptr ctrl_transport( - new uhd::transport::udp( - device_addr["addr"], - boost::lexical_cast(USRP2_UDP_CTRL_PORT) - ) - ); - - //create a data transport - uhd::transport::udp::sptr data_transport( - new uhd::transport::udp( - device_addr["addr"], - boost::lexical_cast(USRP2_UDP_DATA_PORT) - ) - ); - - //create the usrp2 implementation guts - _impl = usrp2_impl::sptr( - new usrp2_impl(ctrl_transport, data_transport) - ); -} - -usrp2::~usrp2(void){ - /* NOP */ -} - -/*********************************************************************** - * Get Properties - **********************************************************************/ -void usrp2::get(const wax::obj &key, wax::obj &val){ - return wax::cast(_impl)->get(key, val); -} - -/*********************************************************************** - * Set Properties - **********************************************************************/ -void usrp2::set(const wax::obj &key, const wax::obj &val){ - return wax::cast(_impl)->set(key, val); -} diff --git a/host/lib/usrp/mboard/usrp2/dboard_impl.cpp b/host/lib/usrp/mboard/usrp2/dboard_impl.cpp deleted file mode 100644 index d127c7f87..000000000 --- a/host/lib/usrp/mboard/usrp2/dboard_impl.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// -// 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 . -// - -#include -#include "usrp2_impl.hpp" -#include "dboard_interface.hpp" - -using namespace uhd; -using namespace uhd::usrp; - -/*********************************************************************** - * Helper Methods - **********************************************************************/ -void usrp2_impl::dboard_init(void){ - //grab the dboard ids over the control line - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO); - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE); - std::cout << boost::format("rx id 0x%.2x, tx id 0x%.2x") - % ntohs(in_data.data.dboard_ids.rx_id) - % ntohs(in_data.data.dboard_ids.tx_id) << std::endl; - - //extract the dboard ids an convert them to enums - dboard::dboard_id_t rx_dboard_id = static_cast( - ntohs(in_data.data.dboard_ids.rx_id) - ); - dboard::dboard_id_t tx_dboard_id = static_cast( - ntohs(in_data.data.dboard_ids.tx_id) - ); - - //create a new dboard interface and manager - dboard::interface::sptr _dboard_interface( - new dboard_interface(this) - ); - dboard::manager::sptr _dboard_manager( - new dboard::manager(rx_dboard_id, tx_dboard_id, _dboard_interface) - ); - - //load dboards - _rx_dboards[""] = wax_obj_proxy( - boost::bind(&usrp2_impl::rx_dboard_get, this, _1, _2), - boost::bind(&usrp2_impl::rx_dboard_set, this, _1, _2) - ); - _tx_dboards[""] = wax_obj_proxy( - boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2), - boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2) - ); -} - -/*********************************************************************** - * RX DBoard Properties - **********************************************************************/ -void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); - - //handle the get request conditioned on the key - switch(wax::cast(key)){ - case DBOARD_PROP_NAME: - val = std::string("usrp2 dboard (rx unit)"); - return; - - case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_rx_subdev(name); - return; - - case DBOARD_PROP_SUBDEV_NAMES: - val = _dboard_manager->get_rx_subdev_names(); - return; - - case DBOARD_PROP_CODEC: - throw std::runtime_error("unhandled prop in usrp2 dboard"); - } -} - -void usrp2_impl::rx_dboard_set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("Cannot set on usrp2 dboard"); -} - -/*********************************************************************** - * TX DBoard Properties - **********************************************************************/ -void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); - - //handle the get request conditioned on the key - switch(wax::cast(key)){ - case DBOARD_PROP_NAME: - val = std::string("usrp2 dboard (tx unit)"); - return; - - case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_tx_subdev(name); - return; - - case DBOARD_PROP_SUBDEV_NAMES: - val = _dboard_manager->get_tx_subdev_names(); - return; - - case DBOARD_PROP_CODEC: - throw std::runtime_error("unhandled prop in usrp2 dboard"); - } -} - -void usrp2_impl::tx_dboard_set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("Cannot set on usrp2 dboard"); -} diff --git a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp b/host/lib/usrp/mboard/usrp2/dboard_interface.cpp deleted file mode 100644 index eb1caaa69..000000000 --- a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp +++ /dev/null @@ -1,284 +0,0 @@ -// -// 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 . -// - -#include -#include "dboard_interface.hpp" -#include "usrp2_impl.hpp" - -using namespace uhd::usrp::dboard; - -/*********************************************************************** - * Structors - **********************************************************************/ -dboard_interface::dboard_interface(usrp2_impl *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(interface::gpio_bank_t bank){ - switch(bank){ - case uhd::usrp::dboard::interface::GPIO_TX_BANK: return USRP2_DIR_TX; - case uhd::usrp::dboard::interface::GPIO_RX_BANK: return USRP2_DIR_RX; - } - throw std::invalid_argument("unknown gpio bank type"); -} - -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); -} - -/*********************************************************************** - * SPI - **********************************************************************/ -/*! - * Static function to convert a spi dev enum - * to an over-the-wire value for the usrp2 control. - * \param dev the dboard interface spi dev enum - * \return an over the wire representation - */ -static uint8_t spi_dev_to_otw(interface::spi_dev_t dev){ - switch(dev){ - case uhd::usrp::dboard::interface::SPI_TX_DEV: return USRP2_DIR_TX; - case uhd::usrp::dboard::interface::SPI_RX_DEV: return USRP2_DIR_RX; - } - throw std::invalid_argument("unknown spi device type"); -} - -/*! - * Static function to convert a spi latch enum - * to an over-the-wire value for the usrp2 control. - * \param latch the dboard interface spi latch enum - * \return an over the wire representation - */ -static uint8_t spi_latch_to_otw(interface::spi_latch_t latch){ - switch(latch){ - case uhd::usrp::dboard::interface::SPI_LATCH_RISE: return USRP2_CLK_EDGE_RISE; - case uhd::usrp::dboard::interface::SPI_LATCH_FALL: return USRP2_CLK_EDGE_FALL; - } - throw std::invalid_argument("unknown spi latch type"); -} - -/*! - * Static function to convert a spi push enum - * to an over-the-wire value for the usrp2 control. - * \param push the dboard interface spi push enum - * \return an over the wire representation - */ -static uint8_t spi_push_to_otw(interface::spi_push_t push){ - switch(push){ - case uhd::usrp::dboard::interface::SPI_PUSH_RISE: return USRP2_CLK_EDGE_RISE; - case uhd::usrp::dboard::interface::SPI_PUSH_FALL: return USRP2_CLK_EDGE_FALL; - } - throw std::invalid_argument("unknown spi push type"); -} - -interface::byte_vector_t dboard_interface::transact_spi( - spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, - const byte_vector_t &buf, - bool readback -){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); - out_data.data.spi_args.dev = spi_dev_to_otw(dev); - out_data.data.spi_args.latch = spi_latch_to_otw(latch); - out_data.data.spi_args.push = spi_push_to_otw(push); - out_data.data.spi_args.readback = (readback)? 1 : 0; - out_data.data.spi_args.bytes = buf.size(); - - //limitation of spi transaction size - ASSERT_THROW(buf.size() <= sizeof(out_data.data.spi_args.data)); - - //copy in the data - for (size_t i = 0; i < buf.size(); i++){ - out_data.data.spi_args.data[i] = buf[i]; - } - - //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_OMG_TRANSACTED_SPI_DUDE); - ASSERT_THROW(in_data.data.spi_args.bytes == buf.size()); - - //copy out the data - byte_vector_t result; - for (size_t i = 0; i < buf.size(); i++){ - result.push_back(in_data.data.spi_args.data[i]); - } - return result; -} - -/*********************************************************************** - * I2C - **********************************************************************/ -void dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO); - out_data.data.i2c_args.addr = i2c_addr; - out_data.data.i2c_args.bytes = buf.size(); - - //limitation of i2c transaction size - ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data)); - - //copy in the data - for (size_t i = 0; i < buf.size(); i++){ - out_data.data.i2c_args.data[i] = buf[i]; - } - - //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_COOL_IM_DONE_I2C_WRITE_DUDE); -} - -interface::byte_vector_t dboard_interface::read_i2c(int i2c_addr, size_t num_bytes){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO); - out_data.data.i2c_args.addr = i2c_addr; - out_data.data.i2c_args.bytes = num_bytes; - - //limitation of i2c transaction size - ASSERT_THROW(num_bytes <= sizeof(out_data.data.i2c_args.data)); - - //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_HERES_THE_I2C_DATA_DUDE); - ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes); - - //copy out the data - byte_vector_t result; - for (size_t i = 0; i < num_bytes; i++){ - result.push_back(in_data.data.i2c_args.data[i]); - } - 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 deleted file mode 100644 index 1040e53ba..000000000 --- a/host/lib/usrp/mboard/usrp2/dboard_interface.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// -// 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 . -// - -#include - -#ifndef INCLUDED_DBOARD_INTERFACE_HPP -#define INCLUDED_DBOARD_INTERFACE_HPP - -class usrp2_impl; //dummy class declaration - -class dboard_interface : public uhd::usrp::dboard::interface{ -public: - dboard_interface(usrp2_impl *impl); - - ~dboard_interface(void); - - void write_aux_dac(unit_type_t, int, int); - - int read_aux_adc(unit_type_t, int); - - 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 write_gpio(gpio_bank_t, uint16_t, uint16_t); - - uint16_t read_gpio(gpio_bank_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); - -private: - byte_vector_t transact_spi( - spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, - const byte_vector_t &buf, - bool readback - ); - - usrp2_impl *_impl; -}; - -#endif /* INCLUDED_DBOARD_INTERFACE_HPP */ diff --git a/host/lib/usrp/mboard/usrp2/dsp_impl.cpp b/host/lib/usrp/mboard/usrp2/dsp_impl.cpp deleted file mode 100644 index 22c00d99a..000000000 --- a/host/lib/usrp/mboard/usrp2/dsp_impl.cpp +++ /dev/null @@ -1,293 +0,0 @@ -// -// 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 . -// - -#include -#include -#include "usrp2_impl.hpp" - -using namespace uhd; - -/*********************************************************************** - * DDC Helper Methods - **********************************************************************/ -static uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t clock_freq){ - double scale_factor = pow(2.0, 32); - - //calculate the freq register word - uint32_t freq_word = rint((freq / clock_freq) * scale_factor); - - //update the actual frequency - freq = (double(freq_word) / scale_factor) * clock_freq; - - return freq_word; -} - -void usrp2_impl::init_ddc_config(void){ - //create the ddc in the rx dsp dict - _rx_dsps["ddc0"] = wax_obj_proxy( - boost::bind(&usrp2_impl::ddc_get, this, _1, _2), - boost::bind(&usrp2_impl::ddc_set, this, _1, _2) - ); - - //initial config and update - _ddc_decim = 16; - _ddc_freq = 0; - update_ddc_config(); - - _ddc_stream_at = time_spec_t(); - _ddc_enabled = false; - update_ddc_enabled(); -} - -void usrp2_impl::update_ddc_config(void){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO); - out_data.data.ddc_args.freq_word = htonl( - calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) - ); - out_data.data.ddc_args.decim = htonl(_ddc_decim); - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE); -} - -void usrp2_impl::update_ddc_enabled(void){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_CONFIGURE_STREAMING_FOR_ME_BRO); - out_data.data.streaming.enabled = (_ddc_enabled)? 1 : 0; - out_data.data.streaming.secs = htonl(_ddc_stream_at.secs); - out_data.data.streaming.ticks = htonl(_ddc_stream_at.ticks); - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_CONFIGURED_THAT_STREAMING_DUDE); - - //clear the stream at time spec (it must be set for the next round of enable/disable) - _ddc_stream_at = time_spec_t(); -} - -/*********************************************************************** - * DDC Properties - **********************************************************************/ -void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){ - //handle the case where the key is an expected dsp property - if (key.type() == typeid(dsp_prop_t)){ - switch(wax::cast(key)){ - case DSP_PROP_NAME: - val = std::string("usrp2 ddc0"); - return; - - case DSP_PROP_OTHERS:{ - prop_names_t others = boost::assign::list_of - ("rate") - ("decim") - ("decim_rates") - ("freq") - ("enabled") - ("stream_at") - ; - val = others; - } - return; - } - } - - //handle string-based properties specific to this dsp - std::string key_name = wax::cast(key); - if (key_name == "rate"){ - val = get_master_clock_freq(); - return; - } - else if (key_name == "decim"){ - val = _ddc_decim; - return; - } - else if (key_name == "decim_rates"){ - val = _allowed_decim_and_interp_rates; - return; - } - else if (key_name == "freq"){ - val = _ddc_freq; - return; - } - else if (key_name == "enabled"){ - val = _ddc_enabled; - return; - } - - throw std::invalid_argument(str( - boost::format("error getting: unknown key with name %s") % key_name - )); -} - -void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ - //handle string-based properties specific to this dsp - std::string key_name = wax::cast(key); - if (key_name == "decim"){ - size_t new_decim = wax::cast(val); - ASSERT_THROW(std::has( - _allowed_decim_and_interp_rates.begin(), - _allowed_decim_and_interp_rates.end(), - new_decim - )); - _ddc_decim = new_decim; //shadow - update_ddc_config(); - return; - } - else if (key_name == "freq"){ - freq_t new_freq = wax::cast(val); - ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); - ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); - _ddc_freq = new_freq; //shadow - update_ddc_config(); - return; - } - else if (key_name == "enabled"){ - bool new_enabled = wax::cast(val); - _ddc_enabled = new_enabled; //shadow - update_ddc_enabled(); - return; - } - else if (key_name == "stream_at"){ - time_spec_t new_stream_at = wax::cast(val); - _ddc_stream_at = new_stream_at; //shadow - //update_ddc_enabled(); //dont update from here - return; - } - - throw std::invalid_argument(str( - boost::format("error setting: unknown key with name %s") % key_name - )); -} - -/*********************************************************************** - * DUC Helper Methods - **********************************************************************/ -void usrp2_impl::init_duc_config(void){ - //create the duc in the tx dsp dict - _tx_dsps["duc0"] = wax_obj_proxy( - boost::bind(&usrp2_impl::duc_get, this, _1, _2), - boost::bind(&usrp2_impl::duc_set, this, _1, _2) - ); - - //initial config and update - _duc_interp = 16; - _duc_freq = 0; - update_duc_config(); -} - -void usrp2_impl::update_duc_config(void){ - // Calculate CIC interpolation (i.e., without halfband interpolators) - size_t tmp_interp = _duc_interp; - while(tmp_interp > 128) tmp_interp /= 2; - - // Calculate closest multiplier constant to reverse gain absent scale multipliers - size_t interp_cubed = pow(tmp_interp, 3); - size_t scale = rint((4096*pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed)); - - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO); - out_data.data.duc_args.freq_word = htonl( - calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq()) - ); - out_data.data.duc_args.interp = htonl(_duc_interp); - out_data.data.duc_args.scale_iq = htonl(scale); - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE); -} - -/*********************************************************************** - * DUC Properties - **********************************************************************/ -void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){ - //handle the case where the key is an expected dsp property - if (key.type() == typeid(dsp_prop_t)){ - switch(wax::cast(key)){ - case DSP_PROP_NAME: - val = std::string("usrp2 duc0"); - return; - - case DSP_PROP_OTHERS:{ - prop_names_t others = boost::assign::list_of - ("rate") - ("interp") - ("interp_rates") - ("freq") - ; - val = others; - } - return; - } - } - - //handle string-based properties specific to this dsp - std::string key_name = wax::cast(key); - if (key_name == "rate"){ - val = get_master_clock_freq(); - return; - } - else if (key_name == "interp"){ - val = _duc_interp; - return; - } - else if (key_name == "interp_rates"){ - val = _allowed_decim_and_interp_rates; - return; - } - else if (key_name == "freq"){ - val = _duc_freq; - return; - } - - throw std::invalid_argument(str( - boost::format("error getting: unknown key with name %s") % key_name - )); -} - -void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ - //handle string-based properties specific to this dsp - std::string key_name = wax::cast(key); - if (key_name == "interp"){ - size_t new_interp = wax::cast(val); - ASSERT_THROW(std::has( - _allowed_decim_and_interp_rates.begin(), - _allowed_decim_and_interp_rates.end(), - new_interp - )); - _duc_interp = new_interp; //shadow - update_duc_config(); - return; - } - else if (key_name == "freq"){ - freq_t new_freq = wax::cast(val); - ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); - ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); - _duc_freq = new_freq; //shadow - update_duc_config(); - return; - } - - throw std::invalid_argument(str( - boost::format("error setting: unknown key with name %s") % key_name - )); -} diff --git a/host/lib/usrp/mboard/usrp2/fw_common.h b/host/lib/usrp/mboard/usrp2/fw_common.h deleted file mode 100644 index 3def8ddaa..000000000 --- a/host/lib/usrp/mboard/usrp2/fw_common.h +++ /dev/null @@ -1,190 +0,0 @@ -// -// 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 . -// - -#ifndef INCLUDED_USRP2_FW_COMMON_H -#define INCLUDED_USRP2_FW_COMMON_H - -/*! - * Structs and constants for usrp2 communication. - * This header is shared by the firmware and host code. - * Therefore, this header may only contain valid C code. - */ -#ifdef __cplusplus -extern "C" { -#endif - -// udp ports for the usrp2 communication -// Dynamic and/or private ports: 49152-65535 -#define USRP2_UDP_CTRL_PORT 49152 -#define USRP2_UDP_DATA_PORT 49153 - -typedef enum{ - USRP2_CTRL_ID_HUH_WHAT, - //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums - //USRP2_CTRL_ID_SUX_MAN, - - USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO, - USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE, - USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO, - - USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO, - USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE, - USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO, - - USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO, - USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE, - - 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_TRANSACT_ME_SOME_SPI_BRO, - USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE, - - USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO, - USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE, - - 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_SETUP_THIS_DDC_FOR_ME_BRO, - USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE, - - USRP2_CTRL_ID_CONFIGURE_STREAMING_FOR_ME_BRO, - USRP2_CTRL_ID_CONFIGURED_THAT_STREAMING_DUDE, - - USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO, - USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE, - - USRP2_CTRL_ID_PEACE_OUT - -} usrp2_ctrl_id_t; - -typedef enum{ - USRP2_PPS_SOURCE_SMA, - USRP2_PPS_SOURCE_MIMO -} usrp2_pps_source_t; - -typedef enum{ - USRP2_PPS_POLARITY_POS, - USRP2_PPS_POLARITY_NEG -} usrp2_pps_polarity_t; - -typedef enum{ - USRP2_REF_SOURCE_INT, - USRP2_REF_SOURCE_SMA, - USRP2_REF_SOURCE_MIMO -} usrp2_ref_source_t; - -typedef enum{ - USRP2_DIR_RX, - USRP2_DIR_TX -} usrp2_dir_which_t; - -typedef enum{ - USRP2_CLK_EDGE_RISE, - USRP2_CLK_EDGE_FALL -} usrp2_clk_edge_t; - -typedef struct{ - uint32_t id; - uint32_t seq; - union{ - uint32_t ip_addr; - uint8_t mac_addr[6]; - struct { - uint16_t rx_id; - uint16_t tx_id; - } dboard_ids; - struct { - uint8_t pps_source; - uint8_t pps_polarity; - uint8_t ref_source; - uint8_t _pad; - } clock_config; - struct { - uint8_t bank; - uint8_t _pad[3]; - uint16_t value; - uint16_t mask; - } gpio_config; - struct { - uint8_t bank; - uint8_t _pad[3]; - uint16_t tx_value; - uint16_t rx_value; - uint16_t mask; - } atr_config; - struct { - uint8_t dev; - uint8_t latch; - uint8_t push; - uint8_t readback; - uint8_t bytes; - uint8_t data[sizeof(uint32_t)]; - } spi_args; - struct { - uint8_t addr; - 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; - struct { - uint32_t freq_word; - uint32_t decim; - } ddc_args; - struct { - uint8_t enabled; - uint8_t _pad[3]; - uint32_t secs; - uint32_t ticks; - } streaming; - struct { - uint32_t freq_word; - uint32_t interp; - uint32_t scale_iq; - } duc_args; - } data; -} usrp2_ctrl_data_t; - -#ifdef __cplusplus -} -#endif - -#endif /* INCLUDED_USRP2_FW_COMMON_H */ diff --git a/host/lib/usrp/mboard/usrp2/mboard_impl.cpp b/host/lib/usrp/mboard/usrp2/mboard_impl.cpp deleted file mode 100644 index 2e4a0715f..000000000 --- a/host/lib/usrp/mboard/usrp2/mboard_impl.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// -// 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 . -// - -#include -#include "usrp2_impl.hpp" - -using namespace uhd; - -/*********************************************************************** - * Helper Methods - **********************************************************************/ -void usrp2_impl::init_clock_config(void){ - //init the pps source clock config - _pps_source_dict["sma"] = USRP2_PPS_SOURCE_SMA; - _pps_source_dict["mimo"] = USRP2_PPS_SOURCE_MIMO; - _pps_source = "sma"; - - //init the pps polarity clock config - _pps_polarity_dict["pos"] = USRP2_PPS_POLARITY_POS; - _pps_polarity_dict["neg"] = USRP2_PPS_POLARITY_NEG; - _pps_polarity = "neg"; - - //init the ref source clock config - _ref_source_dict["int"] = USRP2_REF_SOURCE_INT; - _ref_source_dict["sma"] = USRP2_REF_SOURCE_SMA; - _ref_source_dict["mimo"] = USRP2_REF_SOURCE_MIMO; - _ref_source = "int"; - - //update the clock config (sends a control packet) - update_clock_config(); -} - -void usrp2_impl::update_clock_config(void){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO); - out_data.data.clock_config.pps_source = _pps_source_dict [_pps_source]; - out_data.data.clock_config.pps_polarity = _pps_polarity_dict[_pps_polarity]; - out_data.data.clock_config.ref_source = _ref_source_dict [_ref_source]; - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE); -} - -/*********************************************************************** - * MBoard Get Properties - **********************************************************************/ -void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); - - //handle the get request conditioned on the key - switch(wax::cast(key)){ - case MBOARD_PROP_NAME: - val = std::string("usrp2 mboard"); - return; - - case MBOARD_PROP_OTHERS: - val = prop_names_t(); //empty other props - return; - - case MBOARD_PROP_RX_DBOARD: - val = _rx_dboards[name].get_link(); - return; - - case MBOARD_PROP_RX_DBOARD_NAMES: - val = prop_names_t(_rx_dboards.get_keys()); - return; - - case MBOARD_PROP_TX_DBOARD: - val = _tx_dboards[name].get_link(); - return; - - case MBOARD_PROP_TX_DBOARD_NAMES: - val = prop_names_t(_tx_dboards.get_keys()); - return; - - case MBOARD_PROP_MTU: - // FIXME we dont know the real MTU... - // give them something to fragment about - val = size_t(1500); - return; - - case MBOARD_PROP_CLOCK_RATE: - val = freq_t(get_master_clock_freq()); - return; - - case MBOARD_PROP_RX_DSP: - val = _rx_dsps[name].get_link(); - return; - - case MBOARD_PROP_RX_DSP_NAMES: - val = prop_names_t(_rx_dsps.get_keys()); - return; - - case MBOARD_PROP_TX_DSP: - val = _tx_dsps[name].get_link(); - return; - - case MBOARD_PROP_TX_DSP_NAMES: - val = prop_names_t(_tx_dsps.get_keys()); - return; - - case MBOARD_PROP_PPS_SOURCE: - val = _pps_source; - return; - - case MBOARD_PROP_PPS_SOURCE_NAMES: - val = prop_names_t(_pps_source_dict.get_keys()); - return; - - case MBOARD_PROP_PPS_POLARITY: - val = _pps_polarity; - return; - - case MBOARD_PROP_REF_SOURCE: - val = _ref_source; - return; - - case MBOARD_PROP_REF_SOURCE_NAMES: - val = prop_names_t(_ref_source_dict.get_keys()); - return; - - case MBOARD_PROP_TIME_NOW: - case MBOARD_PROP_TIME_NEXT_PPS: - throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard"); - - } -} - -/*********************************************************************** - * MBoard Set Properties - **********************************************************************/ -void usrp2_impl::set(const wax::obj &key, const wax::obj &val){ - //handle the get request conditioned on the key - switch(wax::cast(key)){ - - case MBOARD_PROP_PPS_SOURCE:{ - std::string name = wax::cast(val); - ASSERT_THROW(_pps_source_dict.has_key(name)); - _pps_source = name; //shadow - update_clock_config(); - } - return; - - case MBOARD_PROP_PPS_POLARITY:{ - std::string name = wax::cast(val); - ASSERT_THROW(_pps_polarity_dict.has_key(name)); - _pps_polarity = name; //shadow - update_clock_config(); - } - return; - - case MBOARD_PROP_REF_SOURCE:{ - std::string name = wax::cast(val); - ASSERT_THROW(_ref_source_dict.has_key(name)); - _ref_source = name; //shadow - update_clock_config(); - } - return; - - case MBOARD_PROP_NAME: - case MBOARD_PROP_OTHERS: - case MBOARD_PROP_MTU: - case MBOARD_PROP_CLOCK_RATE: - case MBOARD_PROP_RX_DSP: - case MBOARD_PROP_RX_DSP_NAMES: - case MBOARD_PROP_TX_DSP: - case MBOARD_PROP_TX_DSP_NAMES: - case MBOARD_PROP_RX_DBOARD: - case MBOARD_PROP_RX_DBOARD_NAMES: - case MBOARD_PROP_TX_DBOARD: - case MBOARD_PROP_TX_DBOARD_NAMES: - case MBOARD_PROP_PPS_SOURCE_NAMES: - case MBOARD_PROP_REF_SOURCE_NAMES: - case MBOARD_PROP_TIME_NOW: - case MBOARD_PROP_TIME_NEXT_PPS: - throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard"); - - } -} diff --git a/host/lib/usrp/mboard/usrp2/usrp2_impl.cpp b/host/lib/usrp/mboard/usrp2/usrp2_impl.cpp deleted file mode 100644 index 39be8938e..000000000 --- a/host/lib/usrp/mboard/usrp2/usrp2_impl.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include "usrp2_impl.hpp" - -using namespace uhd; - -/*********************************************************************** - * Structors - **********************************************************************/ -usrp2_impl::usrp2_impl( - uhd::transport::udp::sptr ctrl_transport, - uhd::transport::udp::sptr data_transport -){ - _ctrl_transport = ctrl_transport; - _data_transport = data_transport; - - //load the allowed decim/interp rates - //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4) - _allowed_decim_and_interp_rates.clear(); - for (size_t i = 4; i <= 128; i+=1){ - _allowed_decim_and_interp_rates.push_back(i); - } - for (size_t i = 130; i <= 256; i+=2){ - _allowed_decim_and_interp_rates.push_back(i); - } - for (size_t i = 260; i <= 512; i+=4){ - _allowed_decim_and_interp_rates.push_back(i); - } - - //init the tx and rx dboards - dboard_init(); - - //init the ddc - init_ddc_config(); - - //init the duc - init_duc_config(); - - //initialize the clock configuration - init_clock_config(); -} - -usrp2_impl::~usrp2_impl(void){ - /* NOP */ -} - -/*********************************************************************** - * Misc Access Methods - **********************************************************************/ -double usrp2_impl::get_master_clock_freq(void){ - return 100e6; -} - -/*********************************************************************** - * Control Send/Recv - **********************************************************************/ -usrp2_ctrl_data_t usrp2_impl::ctrl_send_and_recv(const usrp2_ctrl_data_t &out_data){ - boost::mutex::scoped_lock lock(_ctrl_mutex); - - //fill in the seq number and send - usrp2_ctrl_data_t out_copy = out_data; - out_copy.seq = htonl(++_ctrl_seq_num); - _ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t))); - - //loop and recieve until the time is up - size_t num_timeouts = 0; - while(true){ - uhd::shared_iovec iov = _ctrl_transport->recv(); - if (iov.len < sizeof(usrp2_ctrl_data_t)){ - //sleep a little so we dont burn cpu - if (num_timeouts++ > 50) break; - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - }else{ - //handle the received data - usrp2_ctrl_data_t in_data = *reinterpret_cast(iov.base); - if (ntohl(in_data.seq) == _ctrl_seq_num){ - return in_data; - } - //didnt get seq, continue on... - } - } - throw std::runtime_error("usrp2 no control response"); -} diff --git a/host/lib/usrp/mboard/usrp2/usrp2_impl.hpp b/host/lib/usrp/mboard/usrp2/usrp2_impl.hpp deleted file mode 100644 index 42fe46099..000000000 --- a/host/lib/usrp/mboard/usrp2/usrp2_impl.hpp +++ /dev/null @@ -1,160 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include "fw_common.h" - -#ifndef INCLUDED_USRP2_IMPL_HPP -#define INCLUDED_USRP2_IMPL_HPP - -/*! - * Simple wax obj proxy class: - * Provides a wax obj interface for a set and a get function. - * This allows us to create nested properties structures - * while maintaining flattened code within the implementation. - */ -class wax_obj_proxy : public wax::obj{ -public: - typedef boost::function get_t; - typedef boost::function set_t; - - wax_obj_proxy(void){ - /* NOP */ - } - - wax_obj_proxy(const get_t &get, const set_t &set){ - _get = get; - _set = set; - }; - - ~wax_obj_proxy(void){ - /* NOP */ - } - - void get(const wax::obj &key, wax::obj &val){ - return _get(key, val); - } - - void set(const wax::obj &key, const wax::obj &val){ - return _set(key, val); - } - -private: - get_t _get; - set_t _set; -}; - -/*! - * USRP2 implementation guts: - * The implementation details are encapsulated here. - * Handles properties on the mboard, dboard, dsps... - */ -class usrp2_impl : boost::noncopyable, public wax::obj{ -public: - typedef boost::shared_ptr sptr; - - /*! - * Create a new usrp2 impl base. - * \param ctrl_transport the udp transport for control - * \param data_transport the udp transport for data - */ - usrp2_impl( - uhd::transport::udp::sptr ctrl_transport, - uhd::transport::udp::sptr data_transport - ); - - ~usrp2_impl(void); - - //properties interface - void get(const wax::obj &, wax::obj &); - void set(const wax::obj &, const wax::obj &); - - //performs a control transaction - usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &); - - //misc access methods - double get_master_clock_freq(void); - -private: - //udp transports for control and data - uhd::transport::udp::sptr _ctrl_transport; - uhd::transport::udp::sptr _data_transport; - - //private vars for dealing with send/recv control - uint32_t _ctrl_seq_num; - boost::mutex _ctrl_mutex; - - //methods and shadows for clock configuration - std::string _pps_source, _pps_polarity, _ref_source; - void init_clock_config(void); - void update_clock_config(void); - - //mappings from clock config strings to over the wire enums - uhd::dict _pps_source_dict; - uhd::dict _pps_polarity_dict; - uhd::dict _ref_source_dict; - - //rx and tx dboard methods and objects - uhd::usrp::dboard::manager::sptr _dboard_manager; - void dboard_init(void); - - //properties interface for rx dboard - void rx_dboard_get(const wax::obj &, wax::obj &); - void rx_dboard_set(const wax::obj &, const wax::obj &); - uhd::dict _rx_dboards; - - //properties interface for tx dboard - void tx_dboard_get(const wax::obj &, wax::obj &); - void tx_dboard_set(const wax::obj &, const wax::obj &); - uhd::dict _tx_dboards; - - //methods and shadows for the ddc dsp - std::vector _allowed_decim_and_interp_rates; - size_t _ddc_decim; - uhd::freq_t _ddc_freq; - bool _ddc_enabled; - uhd::time_spec_t _ddc_stream_at; - void init_ddc_config(void); - void update_ddc_config(void); - void update_ddc_enabled(void); - - //methods and shadows for the duc dsp - size_t _duc_interp; - uhd::freq_t _duc_freq; - void init_duc_config(void); - void update_duc_config(void); - - //properties interface for ddc - void ddc_get(const wax::obj &, wax::obj &); - void ddc_set(const wax::obj &, const wax::obj &); - uhd::dict _rx_dsps; - - //properties interface for duc - void duc_get(const wax::obj &, wax::obj &); - void duc_set(const wax::obj &, const wax::obj &); - uhd::dict _tx_dsps; - -}; - -#endif /* INCLUDED_USRP2_IMPL_HPP */ diff --git a/host/lib/usrp/mboard_base.cpp b/host/lib/usrp/mboard_base.cpp new file mode 100644 index 000000000..ccf50794a --- /dev/null +++ b/host/lib/usrp/mboard_base.cpp @@ -0,0 +1,29 @@ +// +// 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 . +// + +#include +#include + +using namespace uhd::usrp; + +mboard_base::mboard_base(void){ + /* NOP */ +} + +mboard_base::~mboard_base(void){ + /* NOP */ +} diff --git a/host/lib/usrp/usrp.cpp b/host/lib/usrp/usrp.cpp index 9b1603a4a..d4bae1694 100644 --- a/host/lib/usrp/usrp.cpp +++ b/host/lib/usrp/usrp.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -48,7 +48,7 @@ usrp::usrp(const device_addr_t &device_addr){ //TODO nothing } else if (device_addr["type"] == "udp"){ - _mboards[""] = mboard::base::sptr(new mboard::usrp2(device_addr)); + _mboards[""] = mboard_base::sptr(new usrp2(device_addr)); } } diff --git a/host/lib/usrp/usrp2.cpp b/host/lib/usrp/usrp2.cpp new file mode 100644 index 000000000..1ff363ae1 --- /dev/null +++ b/host/lib/usrp/usrp2.cpp @@ -0,0 +1,116 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include +#include +#include "usrp2/usrp2_impl.hpp" + +using namespace uhd::usrp; + +/*********************************************************************** + * Discovery over the udp transport + **********************************************************************/ +uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ + device_addrs_t usrp2_addrs; + + //create a udp transport to communicate + //TODO if an addr is not provided, search all interfaces? + std::string ctrl_port = boost::lexical_cast(USRP2_UDP_CTRL_PORT); + uhd::transport::udp udp_transport(hint["addr"], ctrl_port, true); + + //send a hello control packet + usrp2_ctrl_data_t ctrl_data_out; + ctrl_data_out.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO); + udp_transport.send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); + + //loop and recieve until the time is up + size_t num_timeouts = 0; + while(true){ + uhd::shared_iovec iov = udp_transport.recv(); + //std::cout << boost::asio::buffer_size(buff) << "\n"; + if (iov.len < sizeof(usrp2_ctrl_data_t)){ + //sleep a little so we dont burn cpu + if (num_timeouts++ > 50) break; + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + }else{ + //handle the received data + const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast(iov.base); + switch(ntohl(ctrl_data_in->id)){ + case USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE: + //make a boost asio ipv4 with the raw addr in host byte order + boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); + device_addr_t new_addr; + new_addr["name"] = "USRP2"; + new_addr["type"] = "udp"; + new_addr["addr"] = ip_addr.to_string(); + usrp2_addrs.push_back(new_addr); + break; + } + } + } + + return usrp2_addrs; +} + +/*********************************************************************** + * Structors + **********************************************************************/ +usrp2::usrp2(const device_addr_t &device_addr){ + //create a control transport + uhd::transport::udp::sptr ctrl_transport( + new uhd::transport::udp( + device_addr["addr"], + boost::lexical_cast(USRP2_UDP_CTRL_PORT) + ) + ); + + //create a data transport + uhd::transport::udp::sptr data_transport( + new uhd::transport::udp( + device_addr["addr"], + boost::lexical_cast(USRP2_UDP_DATA_PORT) + ) + ); + + //create the usrp2 implementation guts + _impl = usrp2_impl::sptr( + new usrp2_impl(ctrl_transport, data_transport) + ); +} + +usrp2::~usrp2(void){ + /* NOP */ +} + +/*********************************************************************** + * Get Properties + **********************************************************************/ +void usrp2::get(const wax::obj &key, wax::obj &val){ + return wax::cast(_impl)->get(key, val); +} + +/*********************************************************************** + * Set Properties + **********************************************************************/ +void usrp2::set(const wax::obj &key, const wax::obj &val){ + return wax::cast(_impl)->set(key, val); +} diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp new file mode 100644 index 000000000..b38a51b04 --- /dev/null +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -0,0 +1,123 @@ +// +// 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 . +// + +#include +#include "usrp2_impl.hpp" +#include "dboard_interface.hpp" + +using namespace uhd; +using namespace uhd::usrp; + +/*********************************************************************** + * Helper Methods + **********************************************************************/ +void usrp2_impl::dboard_init(void){ + //grab the dboard ids over the control line + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO); + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE); + std::cout << boost::format("rx id 0x%.2x, tx id 0x%.2x") + % ntohs(in_data.data.dboard_ids.rx_id) + % ntohs(in_data.data.dboard_ids.tx_id) << std::endl; + + //extract the dboard ids an convert them to enums + dboard_id_t rx_dboard_id = static_cast( + ntohs(in_data.data.dboard_ids.rx_id) + ); + dboard_id_t tx_dboard_id = static_cast( + ntohs(in_data.data.dboard_ids.tx_id) + ); + + //create a new dboard interface and manager + dboard_interface::sptr _dboard_interface( + new usrp2_dboard_interface(this) + ); + dboard_manager::sptr _dboard_manager( + new dboard_manager(rx_dboard_id, tx_dboard_id, _dboard_interface) + ); + + //load dboards + _rx_dboards[""] = wax_obj_proxy( + boost::bind(&usrp2_impl::rx_dboard_get, this, _1, _2), + boost::bind(&usrp2_impl::rx_dboard_set, this, _1, _2) + ); + _tx_dboards[""] = wax_obj_proxy( + boost::bind(&usrp2_impl::tx_dboard_get, this, _1, _2), + boost::bind(&usrp2_impl::tx_dboard_set, this, _1, _2) + ); +} + +/*********************************************************************** + * RX DBoard Properties + **********************************************************************/ +void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(wax::cast(key)){ + case DBOARD_PROP_NAME: + val = std::string("usrp2 dboard (rx unit)"); + return; + + case DBOARD_PROP_SUBDEV: + val = _dboard_manager->get_rx_subdev(name); + return; + + case DBOARD_PROP_SUBDEV_NAMES: + val = _dboard_manager->get_rx_subdev_names(); + return; + + case DBOARD_PROP_CODEC: + throw std::runtime_error("unhandled prop in usrp2 dboard"); + } +} + +void usrp2_impl::rx_dboard_set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("Cannot set on usrp2 dboard"); +} + +/*********************************************************************** + * TX DBoard Properties + **********************************************************************/ +void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(wax::cast(key)){ + case DBOARD_PROP_NAME: + val = std::string("usrp2 dboard (tx unit)"); + return; + + case DBOARD_PROP_SUBDEV: + val = _dboard_manager->get_tx_subdev(name); + return; + + case DBOARD_PROP_SUBDEV_NAMES: + val = _dboard_manager->get_tx_subdev_names(); + return; + + case DBOARD_PROP_CODEC: + throw std::runtime_error("unhandled prop in usrp2 dboard"); + } +} + +void usrp2_impl::tx_dboard_set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("Cannot set on usrp2 dboard"); +} diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp new file mode 100644 index 000000000..f12b101f3 --- /dev/null +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -0,0 +1,284 @@ +// +// 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 . +// + +#include +#include "dboard_interface.hpp" +#include "usrp2_impl.hpp" + +using namespace uhd::usrp; + +/*********************************************************************** + * Structors + **********************************************************************/ +usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){ + _impl = impl; +} + +usrp2_dboard_interface::~usrp2_dboard_interface(void){ + /* NOP */ +} + +/*********************************************************************** + * Clock Rates + **********************************************************************/ +double usrp2_dboard_interface::get_rx_clock_rate(void){ + return _impl->get_master_clock_freq(); +} + +double usrp2_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(dboard_interface::gpio_bank_t bank){ + switch(bank){ + case uhd::usrp::dboard_interface::GPIO_TX_BANK: return USRP2_DIR_TX; + case uhd::usrp::dboard_interface::GPIO_RX_BANK: return USRP2_DIR_RX; + } + throw std::invalid_argument("unknown gpio bank type"); +} + +void usrp2_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 usrp2_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 usrp2_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 usrp2_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); +} + +/*********************************************************************** + * SPI + **********************************************************************/ +/*! + * Static function to convert a spi dev enum + * to an over-the-wire value for the usrp2 control. + * \param dev the dboard interface spi dev enum + * \return an over the wire representation + */ +static uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){ + switch(dev){ + case uhd::usrp::dboard_interface::SPI_TX_DEV: return USRP2_DIR_TX; + case uhd::usrp::dboard_interface::SPI_RX_DEV: return USRP2_DIR_RX; + } + throw std::invalid_argument("unknown spi device type"); +} + +/*! + * Static function to convert a spi latch enum + * to an over-the-wire value for the usrp2 control. + * \param latch the dboard interface spi latch enum + * \return an over the wire representation + */ +static uint8_t spi_latch_to_otw(dboard_interface::spi_latch_t latch){ + switch(latch){ + case uhd::usrp::dboard_interface::SPI_LATCH_RISE: return USRP2_CLK_EDGE_RISE; + case uhd::usrp::dboard_interface::SPI_LATCH_FALL: return USRP2_CLK_EDGE_FALL; + } + throw std::invalid_argument("unknown spi latch type"); +} + +/*! + * Static function to convert a spi push enum + * to an over-the-wire value for the usrp2 control. + * \param push the dboard interface spi push enum + * \return an over the wire representation + */ +static uint8_t spi_push_to_otw(dboard_interface::spi_push_t push){ + switch(push){ + case uhd::usrp::dboard_interface::SPI_PUSH_RISE: return USRP2_CLK_EDGE_RISE; + case uhd::usrp::dboard_interface::SPI_PUSH_FALL: return USRP2_CLK_EDGE_FALL; + } + throw std::invalid_argument("unknown spi push type"); +} + +dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi( + spi_dev_t dev, + spi_latch_t latch, + spi_push_t push, + const byte_vector_t &buf, + bool readback +){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); + out_data.data.spi_args.dev = spi_dev_to_otw(dev); + out_data.data.spi_args.latch = spi_latch_to_otw(latch); + out_data.data.spi_args.push = spi_push_to_otw(push); + out_data.data.spi_args.readback = (readback)? 1 : 0; + out_data.data.spi_args.bytes = buf.size(); + + //limitation of spi transaction size + ASSERT_THROW(buf.size() <= sizeof(out_data.data.spi_args.data)); + + //copy in the data + for (size_t i = 0; i < buf.size(); i++){ + out_data.data.spi_args.data[i] = buf[i]; + } + + //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_OMG_TRANSACTED_SPI_DUDE); + ASSERT_THROW(in_data.data.spi_args.bytes == buf.size()); + + //copy out the data + byte_vector_t result; + for (size_t i = 0; i < buf.size(); i++){ + result.push_back(in_data.data.spi_args.data[i]); + } + return result; +} + +/*********************************************************************** + * I2C + **********************************************************************/ +void usrp2_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO); + out_data.data.i2c_args.addr = i2c_addr; + out_data.data.i2c_args.bytes = buf.size(); + + //limitation of i2c transaction size + ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data)); + + //copy in the data + for (size_t i = 0; i < buf.size(); i++){ + out_data.data.i2c_args.data[i] = buf[i]; + } + + //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_COOL_IM_DONE_I2C_WRITE_DUDE); +} + +dboard_interface::byte_vector_t usrp2_dboard_interface::read_i2c(int i2c_addr, size_t num_bytes){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO); + out_data.data.i2c_args.addr = i2c_addr; + out_data.data.i2c_args.bytes = num_bytes; + + //limitation of i2c transaction size + ASSERT_THROW(num_bytes <= sizeof(out_data.data.i2c_args.data)); + + //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_HERES_THE_I2C_DATA_DUDE); + ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes); + + //copy out the data + byte_vector_t result; + for (size_t i = 0; i < num_bytes; i++){ + result.push_back(in_data.data.i2c_args.data[i]); + } + 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(dboard_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 usrp2_dboard_interface::write_aux_dac(dboard_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 usrp2_dboard_interface::read_aux_adc(dboard_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/usrp2/dboard_interface.hpp b/host/lib/usrp/usrp2/dboard_interface.hpp new file mode 100644 index 000000000..a06359e5e --- /dev/null +++ b/host/lib/usrp/usrp2/dboard_interface.hpp @@ -0,0 +1,63 @@ +// +// 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 . +// + +#include + +#ifndef INCLUDED_DBOARD_INTERFACE_HPP +#define INCLUDED_DBOARD_INTERFACE_HPP + +class usrp2_impl; //dummy class declaration + +class usrp2_dboard_interface : public uhd::usrp::dboard_interface{ +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 set_atr_reg(gpio_bank_t, uint16_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); + + uint16_t read_gpio(gpio_bank_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); + +private: + byte_vector_t transact_spi( + spi_dev_t dev, + spi_latch_t latch, + spi_push_t push, + const byte_vector_t &buf, + bool readback + ); + + usrp2_impl *_impl; +}; + +#endif /* INCLUDED_DBOARD_INTERFACE_HPP */ diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp new file mode 100644 index 000000000..22c00d99a --- /dev/null +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -0,0 +1,293 @@ +// +// 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 . +// + +#include +#include +#include "usrp2_impl.hpp" + +using namespace uhd; + +/*********************************************************************** + * DDC Helper Methods + **********************************************************************/ +static uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t clock_freq){ + double scale_factor = pow(2.0, 32); + + //calculate the freq register word + uint32_t freq_word = rint((freq / clock_freq) * scale_factor); + + //update the actual frequency + freq = (double(freq_word) / scale_factor) * clock_freq; + + return freq_word; +} + +void usrp2_impl::init_ddc_config(void){ + //create the ddc in the rx dsp dict + _rx_dsps["ddc0"] = wax_obj_proxy( + boost::bind(&usrp2_impl::ddc_get, this, _1, _2), + boost::bind(&usrp2_impl::ddc_set, this, _1, _2) + ); + + //initial config and update + _ddc_decim = 16; + _ddc_freq = 0; + update_ddc_config(); + + _ddc_stream_at = time_spec_t(); + _ddc_enabled = false; + update_ddc_enabled(); +} + +void usrp2_impl::update_ddc_config(void){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO); + out_data.data.ddc_args.freq_word = htonl( + calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) + ); + out_data.data.ddc_args.decim = htonl(_ddc_decim); + + //send and recv + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE); +} + +void usrp2_impl::update_ddc_enabled(void){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_CONFIGURE_STREAMING_FOR_ME_BRO); + out_data.data.streaming.enabled = (_ddc_enabled)? 1 : 0; + out_data.data.streaming.secs = htonl(_ddc_stream_at.secs); + out_data.data.streaming.ticks = htonl(_ddc_stream_at.ticks); + + //send and recv + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_CONFIGURED_THAT_STREAMING_DUDE); + + //clear the stream at time spec (it must be set for the next round of enable/disable) + _ddc_stream_at = time_spec_t(); +} + +/*********************************************************************** + * DDC Properties + **********************************************************************/ +void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){ + //handle the case where the key is an expected dsp property + if (key.type() == typeid(dsp_prop_t)){ + switch(wax::cast(key)){ + case DSP_PROP_NAME: + val = std::string("usrp2 ddc0"); + return; + + case DSP_PROP_OTHERS:{ + prop_names_t others = boost::assign::list_of + ("rate") + ("decim") + ("decim_rates") + ("freq") + ("enabled") + ("stream_at") + ; + val = others; + } + return; + } + } + + //handle string-based properties specific to this dsp + std::string key_name = wax::cast(key); + if (key_name == "rate"){ + val = get_master_clock_freq(); + return; + } + else if (key_name == "decim"){ + val = _ddc_decim; + return; + } + else if (key_name == "decim_rates"){ + val = _allowed_decim_and_interp_rates; + return; + } + else if (key_name == "freq"){ + val = _ddc_freq; + return; + } + else if (key_name == "enabled"){ + val = _ddc_enabled; + return; + } + + throw std::invalid_argument(str( + boost::format("error getting: unknown key with name %s") % key_name + )); +} + +void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ + //handle string-based properties specific to this dsp + std::string key_name = wax::cast(key); + if (key_name == "decim"){ + size_t new_decim = wax::cast(val); + ASSERT_THROW(std::has( + _allowed_decim_and_interp_rates.begin(), + _allowed_decim_and_interp_rates.end(), + new_decim + )); + _ddc_decim = new_decim; //shadow + update_ddc_config(); + return; + } + else if (key_name == "freq"){ + freq_t new_freq = wax::cast(val); + ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); + ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); + _ddc_freq = new_freq; //shadow + update_ddc_config(); + return; + } + else if (key_name == "enabled"){ + bool new_enabled = wax::cast(val); + _ddc_enabled = new_enabled; //shadow + update_ddc_enabled(); + return; + } + else if (key_name == "stream_at"){ + time_spec_t new_stream_at = wax::cast(val); + _ddc_stream_at = new_stream_at; //shadow + //update_ddc_enabled(); //dont update from here + return; + } + + throw std::invalid_argument(str( + boost::format("error setting: unknown key with name %s") % key_name + )); +} + +/*********************************************************************** + * DUC Helper Methods + **********************************************************************/ +void usrp2_impl::init_duc_config(void){ + //create the duc in the tx dsp dict + _tx_dsps["duc0"] = wax_obj_proxy( + boost::bind(&usrp2_impl::duc_get, this, _1, _2), + boost::bind(&usrp2_impl::duc_set, this, _1, _2) + ); + + //initial config and update + _duc_interp = 16; + _duc_freq = 0; + update_duc_config(); +} + +void usrp2_impl::update_duc_config(void){ + // Calculate CIC interpolation (i.e., without halfband interpolators) + size_t tmp_interp = _duc_interp; + while(tmp_interp > 128) tmp_interp /= 2; + + // Calculate closest multiplier constant to reverse gain absent scale multipliers + size_t interp_cubed = pow(tmp_interp, 3); + size_t scale = rint((4096*pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed)); + + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO); + out_data.data.duc_args.freq_word = htonl( + calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq()) + ); + out_data.data.duc_args.interp = htonl(_duc_interp); + out_data.data.duc_args.scale_iq = htonl(scale); + + //send and recv + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE); +} + +/*********************************************************************** + * DUC Properties + **********************************************************************/ +void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){ + //handle the case where the key is an expected dsp property + if (key.type() == typeid(dsp_prop_t)){ + switch(wax::cast(key)){ + case DSP_PROP_NAME: + val = std::string("usrp2 duc0"); + return; + + case DSP_PROP_OTHERS:{ + prop_names_t others = boost::assign::list_of + ("rate") + ("interp") + ("interp_rates") + ("freq") + ; + val = others; + } + return; + } + } + + //handle string-based properties specific to this dsp + std::string key_name = wax::cast(key); + if (key_name == "rate"){ + val = get_master_clock_freq(); + return; + } + else if (key_name == "interp"){ + val = _duc_interp; + return; + } + else if (key_name == "interp_rates"){ + val = _allowed_decim_and_interp_rates; + return; + } + else if (key_name == "freq"){ + val = _duc_freq; + return; + } + + throw std::invalid_argument(str( + boost::format("error getting: unknown key with name %s") % key_name + )); +} + +void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ + //handle string-based properties specific to this dsp + std::string key_name = wax::cast(key); + if (key_name == "interp"){ + size_t new_interp = wax::cast(val); + ASSERT_THROW(std::has( + _allowed_decim_and_interp_rates.begin(), + _allowed_decim_and_interp_rates.end(), + new_interp + )); + _duc_interp = new_interp; //shadow + update_duc_config(); + return; + } + else if (key_name == "freq"){ + freq_t new_freq = wax::cast(val); + ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); + ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); + _duc_freq = new_freq; //shadow + update_duc_config(); + return; + } + + throw std::invalid_argument(str( + boost::format("error setting: unknown key with name %s") % key_name + )); +} diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h new file mode 100644 index 000000000..3def8ddaa --- /dev/null +++ b/host/lib/usrp/usrp2/fw_common.h @@ -0,0 +1,190 @@ +// +// 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 . +// + +#ifndef INCLUDED_USRP2_FW_COMMON_H +#define INCLUDED_USRP2_FW_COMMON_H + +/*! + * Structs and constants for usrp2 communication. + * This header is shared by the firmware and host code. + * Therefore, this header may only contain valid C code. + */ +#ifdef __cplusplus +extern "C" { +#endif + +// udp ports for the usrp2 communication +// Dynamic and/or private ports: 49152-65535 +#define USRP2_UDP_CTRL_PORT 49152 +#define USRP2_UDP_DATA_PORT 49153 + +typedef enum{ + USRP2_CTRL_ID_HUH_WHAT, + //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums + //USRP2_CTRL_ID_SUX_MAN, + + USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO, + USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE, + USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO, + + USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO, + USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE, + USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO, + + USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO, + USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE, + + 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_TRANSACT_ME_SOME_SPI_BRO, + USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE, + + USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO, + USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE, + + 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_SETUP_THIS_DDC_FOR_ME_BRO, + USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE, + + USRP2_CTRL_ID_CONFIGURE_STREAMING_FOR_ME_BRO, + USRP2_CTRL_ID_CONFIGURED_THAT_STREAMING_DUDE, + + USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO, + USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE, + + USRP2_CTRL_ID_PEACE_OUT + +} usrp2_ctrl_id_t; + +typedef enum{ + USRP2_PPS_SOURCE_SMA, + USRP2_PPS_SOURCE_MIMO +} usrp2_pps_source_t; + +typedef enum{ + USRP2_PPS_POLARITY_POS, + USRP2_PPS_POLARITY_NEG +} usrp2_pps_polarity_t; + +typedef enum{ + USRP2_REF_SOURCE_INT, + USRP2_REF_SOURCE_SMA, + USRP2_REF_SOURCE_MIMO +} usrp2_ref_source_t; + +typedef enum{ + USRP2_DIR_RX, + USRP2_DIR_TX +} usrp2_dir_which_t; + +typedef enum{ + USRP2_CLK_EDGE_RISE, + USRP2_CLK_EDGE_FALL +} usrp2_clk_edge_t; + +typedef struct{ + uint32_t id; + uint32_t seq; + union{ + uint32_t ip_addr; + uint8_t mac_addr[6]; + struct { + uint16_t rx_id; + uint16_t tx_id; + } dboard_ids; + struct { + uint8_t pps_source; + uint8_t pps_polarity; + uint8_t ref_source; + uint8_t _pad; + } clock_config; + struct { + uint8_t bank; + uint8_t _pad[3]; + uint16_t value; + uint16_t mask; + } gpio_config; + struct { + uint8_t bank; + uint8_t _pad[3]; + uint16_t tx_value; + uint16_t rx_value; + uint16_t mask; + } atr_config; + struct { + uint8_t dev; + uint8_t latch; + uint8_t push; + uint8_t readback; + uint8_t bytes; + uint8_t data[sizeof(uint32_t)]; + } spi_args; + struct { + uint8_t addr; + 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; + struct { + uint32_t freq_word; + uint32_t decim; + } ddc_args; + struct { + uint8_t enabled; + uint8_t _pad[3]; + uint32_t secs; + uint32_t ticks; + } streaming; + struct { + uint32_t freq_word; + uint32_t interp; + uint32_t scale_iq; + } duc_args; + } data; +} usrp2_ctrl_data_t; + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDED_USRP2_FW_COMMON_H */ diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp new file mode 100644 index 000000000..2e4a0715f --- /dev/null +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -0,0 +1,196 @@ +// +// 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 . +// + +#include +#include "usrp2_impl.hpp" + +using namespace uhd; + +/*********************************************************************** + * Helper Methods + **********************************************************************/ +void usrp2_impl::init_clock_config(void){ + //init the pps source clock config + _pps_source_dict["sma"] = USRP2_PPS_SOURCE_SMA; + _pps_source_dict["mimo"] = USRP2_PPS_SOURCE_MIMO; + _pps_source = "sma"; + + //init the pps polarity clock config + _pps_polarity_dict["pos"] = USRP2_PPS_POLARITY_POS; + _pps_polarity_dict["neg"] = USRP2_PPS_POLARITY_NEG; + _pps_polarity = "neg"; + + //init the ref source clock config + _ref_source_dict["int"] = USRP2_REF_SOURCE_INT; + _ref_source_dict["sma"] = USRP2_REF_SOURCE_SMA; + _ref_source_dict["mimo"] = USRP2_REF_SOURCE_MIMO; + _ref_source = "int"; + + //update the clock config (sends a control packet) + update_clock_config(); +} + +void usrp2_impl::update_clock_config(void){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO); + out_data.data.clock_config.pps_source = _pps_source_dict [_pps_source]; + out_data.data.clock_config.pps_polarity = _pps_polarity_dict[_pps_polarity]; + out_data.data.clock_config.ref_source = _ref_source_dict [_ref_source]; + + //send and recv + usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE); +} + +/*********************************************************************** + * MBoard Get Properties + **********************************************************************/ +void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(wax::cast(key)){ + case MBOARD_PROP_NAME: + val = std::string("usrp2 mboard"); + return; + + case MBOARD_PROP_OTHERS: + val = prop_names_t(); //empty other props + return; + + case MBOARD_PROP_RX_DBOARD: + val = _rx_dboards[name].get_link(); + return; + + case MBOARD_PROP_RX_DBOARD_NAMES: + val = prop_names_t(_rx_dboards.get_keys()); + return; + + case MBOARD_PROP_TX_DBOARD: + val = _tx_dboards[name].get_link(); + return; + + case MBOARD_PROP_TX_DBOARD_NAMES: + val = prop_names_t(_tx_dboards.get_keys()); + return; + + case MBOARD_PROP_MTU: + // FIXME we dont know the real MTU... + // give them something to fragment about + val = size_t(1500); + return; + + case MBOARD_PROP_CLOCK_RATE: + val = freq_t(get_master_clock_freq()); + return; + + case MBOARD_PROP_RX_DSP: + val = _rx_dsps[name].get_link(); + return; + + case MBOARD_PROP_RX_DSP_NAMES: + val = prop_names_t(_rx_dsps.get_keys()); + return; + + case MBOARD_PROP_TX_DSP: + val = _tx_dsps[name].get_link(); + return; + + case MBOARD_PROP_TX_DSP_NAMES: + val = prop_names_t(_tx_dsps.get_keys()); + return; + + case MBOARD_PROP_PPS_SOURCE: + val = _pps_source; + return; + + case MBOARD_PROP_PPS_SOURCE_NAMES: + val = prop_names_t(_pps_source_dict.get_keys()); + return; + + case MBOARD_PROP_PPS_POLARITY: + val = _pps_polarity; + return; + + case MBOARD_PROP_REF_SOURCE: + val = _ref_source; + return; + + case MBOARD_PROP_REF_SOURCE_NAMES: + val = prop_names_t(_ref_source_dict.get_keys()); + return; + + case MBOARD_PROP_TIME_NOW: + case MBOARD_PROP_TIME_NEXT_PPS: + throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard"); + + } +} + +/*********************************************************************** + * MBoard Set Properties + **********************************************************************/ +void usrp2_impl::set(const wax::obj &key, const wax::obj &val){ + //handle the get request conditioned on the key + switch(wax::cast(key)){ + + case MBOARD_PROP_PPS_SOURCE:{ + std::string name = wax::cast(val); + ASSERT_THROW(_pps_source_dict.has_key(name)); + _pps_source = name; //shadow + update_clock_config(); + } + return; + + case MBOARD_PROP_PPS_POLARITY:{ + std::string name = wax::cast(val); + ASSERT_THROW(_pps_polarity_dict.has_key(name)); + _pps_polarity = name; //shadow + update_clock_config(); + } + return; + + case MBOARD_PROP_REF_SOURCE:{ + std::string name = wax::cast(val); + ASSERT_THROW(_ref_source_dict.has_key(name)); + _ref_source = name; //shadow + update_clock_config(); + } + return; + + case MBOARD_PROP_NAME: + case MBOARD_PROP_OTHERS: + case MBOARD_PROP_MTU: + case MBOARD_PROP_CLOCK_RATE: + case MBOARD_PROP_RX_DSP: + case MBOARD_PROP_RX_DSP_NAMES: + case MBOARD_PROP_TX_DSP: + case MBOARD_PROP_TX_DSP_NAMES: + case MBOARD_PROP_RX_DBOARD: + case MBOARD_PROP_RX_DBOARD_NAMES: + case MBOARD_PROP_TX_DBOARD: + case MBOARD_PROP_TX_DBOARD_NAMES: + case MBOARD_PROP_PPS_SOURCE_NAMES: + case MBOARD_PROP_REF_SOURCE_NAMES: + case MBOARD_PROP_TIME_NOW: + case MBOARD_PROP_TIME_NEXT_PPS: + throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard"); + + } +} diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp new file mode 100644 index 000000000..dbf740f2b --- /dev/null +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -0,0 +1,102 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include "usrp2_impl.hpp" + +using namespace uhd; + +/*********************************************************************** + * Structors + **********************************************************************/ +usrp2_impl::usrp2_impl( + uhd::transport::udp::sptr ctrl_transport, + uhd::transport::udp::sptr data_transport +){ + _ctrl_transport = ctrl_transport; + _data_transport = data_transport; + + //load the allowed decim/interp rates + //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4) + _allowed_decim_and_interp_rates.clear(); + for (size_t i = 4; i <= 128; i+=1){ + _allowed_decim_and_interp_rates.push_back(i); + } + for (size_t i = 130; i <= 256; i+=2){ + _allowed_decim_and_interp_rates.push_back(i); + } + for (size_t i = 260; i <= 512; i+=4){ + _allowed_decim_and_interp_rates.push_back(i); + } + + //init the tx and rx dboards + dboard_init(); + + //init the ddc + init_ddc_config(); + + //init the duc + init_duc_config(); + + //initialize the clock configuration + init_clock_config(); +} + +usrp2_impl::~usrp2_impl(void){ + /* NOP */ +} + +/*********************************************************************** + * Misc Access Methods + **********************************************************************/ +double usrp2_impl::get_master_clock_freq(void){ + return 100e6; +} + +/*********************************************************************** + * Control Send/Recv + **********************************************************************/ +usrp2_ctrl_data_t usrp2_impl::ctrl_send_and_recv(const usrp2_ctrl_data_t &out_data){ + boost::mutex::scoped_lock lock(_ctrl_mutex); + + //fill in the seq number and send + usrp2_ctrl_data_t out_copy = out_data; + out_copy.seq = htonl(++_ctrl_seq_num); + _ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t))); + + //loop and recieve until the time is up + size_t num_timeouts = 0; + while(true){ + uhd::shared_iovec iov = _ctrl_transport->recv(); + if (iov.len < sizeof(usrp2_ctrl_data_t)){ + //sleep a little so we dont burn cpu + if (num_timeouts++ > 50) break; + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + }else{ + //handle the received data + usrp2_ctrl_data_t in_data = *reinterpret_cast(iov.base); + if (ntohl(in_data.seq) == _ctrl_seq_num){ + return in_data; + } + //didnt get seq, continue on... + } + } + throw std::runtime_error("usrp2 no control response"); +} diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp new file mode 100644 index 000000000..be457a91c --- /dev/null +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -0,0 +1,160 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "fw_common.h" + +#ifndef INCLUDED_USRP2_IMPL_HPP +#define INCLUDED_USRP2_IMPL_HPP + +/*! + * Simple wax obj proxy class: + * Provides a wax obj interface for a set and a get function. + * This allows us to create nested properties structures + * while maintaining flattened code within the implementation. + */ +class wax_obj_proxy : public wax::obj{ +public: + typedef boost::function get_t; + typedef boost::function set_t; + + wax_obj_proxy(void){ + /* NOP */ + } + + wax_obj_proxy(const get_t &get, const set_t &set){ + _get = get; + _set = set; + }; + + ~wax_obj_proxy(void){ + /* NOP */ + } + + void get(const wax::obj &key, wax::obj &val){ + return _get(key, val); + } + + void set(const wax::obj &key, const wax::obj &val){ + return _set(key, val); + } + +private: + get_t _get; + set_t _set; +}; + +/*! + * USRP2 implementation guts: + * The implementation details are encapsulated here. + * Handles properties on the mboard, dboard, dsps... + */ +class usrp2_impl : boost::noncopyable, public wax::obj{ +public: + typedef boost::shared_ptr sptr; + + /*! + * Create a new usrp2 impl base. + * \param ctrl_transport the udp transport for control + * \param data_transport the udp transport for data + */ + usrp2_impl( + uhd::transport::udp::sptr ctrl_transport, + uhd::transport::udp::sptr data_transport + ); + + ~usrp2_impl(void); + + //properties interface + void get(const wax::obj &, wax::obj &); + void set(const wax::obj &, const wax::obj &); + + //performs a control transaction + usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &); + + //misc access methods + double get_master_clock_freq(void); + +private: + //udp transports for control and data + uhd::transport::udp::sptr _ctrl_transport; + uhd::transport::udp::sptr _data_transport; + + //private vars for dealing with send/recv control + uint32_t _ctrl_seq_num; + boost::mutex _ctrl_mutex; + + //methods and shadows for clock configuration + std::string _pps_source, _pps_polarity, _ref_source; + void init_clock_config(void); + void update_clock_config(void); + + //mappings from clock config strings to over the wire enums + uhd::dict _pps_source_dict; + uhd::dict _pps_polarity_dict; + uhd::dict _ref_source_dict; + + //rx and tx dboard methods and objects + uhd::usrp::dboard_manager::sptr _dboard_manager; + void dboard_init(void); + + //properties interface for rx dboard + void rx_dboard_get(const wax::obj &, wax::obj &); + void rx_dboard_set(const wax::obj &, const wax::obj &); + uhd::dict _rx_dboards; + + //properties interface for tx dboard + void tx_dboard_get(const wax::obj &, wax::obj &); + void tx_dboard_set(const wax::obj &, const wax::obj &); + uhd::dict _tx_dboards; + + //methods and shadows for the ddc dsp + std::vector _allowed_decim_and_interp_rates; + size_t _ddc_decim; + uhd::freq_t _ddc_freq; + bool _ddc_enabled; + uhd::time_spec_t _ddc_stream_at; + void init_ddc_config(void); + void update_ddc_config(void); + void update_ddc_enabled(void); + + //methods and shadows for the duc dsp + size_t _duc_interp; + uhd::freq_t _duc_freq; + void init_duc_config(void); + void update_duc_config(void); + + //properties interface for ddc + void ddc_get(const wax::obj &, wax::obj &); + void ddc_set(const wax::obj &, const wax::obj &); + uhd::dict _rx_dsps; + + //properties interface for duc + void duc_get(const wax::obj &, wax::obj &); + void duc_set(const wax::obj &, const wax::obj &); + uhd::dict _tx_dsps; + +}; + +#endif /* INCLUDED_USRP2_IMPL_HPP */ -- cgit v1.2.3