From 632ca4afbbc2e383b956a7abe8e35ee1020c7306 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Apr 2010 15:31:01 -0700 Subject: added automatic ref source enum --- host/include/uhd/types/clock_config.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'host/include') diff --git a/host/include/uhd/types/clock_config.hpp b/host/include/uhd/types/clock_config.hpp index 42d74ad90..9342fbb7b 100644 --- a/host/include/uhd/types/clock_config.hpp +++ b/host/include/uhd/types/clock_config.hpp @@ -29,6 +29,7 @@ namespace uhd{ */ struct UHD_API clock_config_t{ enum ref_source_t { + REF_AUTO = 'a', //automatic (device specific) REF_INT = 'i', //internal reference REF_SMA = 's', //external sma port REF_MIMO = 'm' //mimo cable (usrp2 only) -- cgit v1.2.3 From 8375ae721cd819b54fae4cc22e76285552033945 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Apr 2010 22:10:35 -0700 Subject: moved spi and i2c api into serial.hpp, its used for more than the dboard interfacing --- host/include/uhd/types/CMakeLists.txt | 1 + host/include/uhd/types/io_type.hpp | 1 + host/include/uhd/types/serial.hpp | 61 ++++++++++++++++++++++++++++++++++ host/include/uhd/usrp/dboard_iface.hpp | 30 +---------------- host/lib/types.cpp | 9 +++++ host/lib/usrp/usrp2/clock_control.cpp | 1 + host/lib/usrp/usrp2/dboard_iface.cpp | 6 ++-- host/lib/usrp/usrp2/usrp2_iface.cpp | 1 - host/lib/usrp/usrp2/usrp2_iface.hpp | 4 +-- 9 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 host/include/uhd/types/serial.hpp (limited to 'host/include') diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index e4cdf2cef..dbce21c98 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -25,6 +25,7 @@ INSTALL(FILES metadata.hpp otw_type.hpp ranges.hpp + serial.hpp stream_cmd.hpp time_spec.hpp tune_result.hpp diff --git a/host/include/uhd/types/io_type.hpp b/host/include/uhd/types/io_type.hpp index 930394d1b..5176374d6 100644 --- a/host/include/uhd/types/io_type.hpp +++ b/host/include/uhd/types/io_type.hpp @@ -23,6 +23,7 @@ namespace uhd{ /*! + * The Input/Output configuration struct: * Used to specify the IO type with device send/recv. */ class UHD_API io_type_t{ diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp new file mode 100644 index 000000000..b0fe5d7bd --- /dev/null +++ b/host/include/uhd/types/serial.hpp @@ -0,0 +1,61 @@ +// +// 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_UHD_TYPES_SERIAL_HPP +#define INCLUDED_UHD_TYPES_SERIAL_HPP + +#include +#include +#include + +namespace uhd{ + + /*! + * Byte vector typedef for passing data in and out of I2C interfaces. + */ + typedef std::vector byte_vector_t; + + /*! + * The SPI configuration struct: + * Used to configure a SPI transaction interface. + */ + struct UHD_API spi_config_t{ + /*! + * The edge type specifies when data is valid + * relative to the edge of the serial clock. + */ + enum edge_t{ + EDGE_RISE = 'r', + EDGE_FALL = 'f' + }; + + //! on what edge is the mosi data valid? + edge_t mosi_edge; + + //! on what edge is the miso data valid? + edge_t miso_edge; + + /*! + * Create a new spi config. + * \param edge the default edge for mosi and miso + */ + spi_config_t(edge_t edge = EDGE_RISE); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_SERIAL_HPP */ diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index 71c7be200..79b8ee664 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -19,39 +19,12 @@ #define INCLUDED_UHD_USRP_DBOARD_IFACE_HPP #include +#include #include #include -#include namespace uhd{ namespace usrp{ -//spi configuration struct -struct UHD_API spi_config_t{ - /*! - * The edge type specifies when data is valid - * relative to the edge of the serial clock. - */ - enum edge_t{ - EDGE_RISE = 'r', - EDGE_FALL = 'f' - }; - - //! on what edge is the mosi data valid? - edge_t mosi_edge; - - //! on what edge is the miso data valid? - edge_t miso_edge; - - /*! - * Create a new spi config. - * \param edge the default edge for mosi and miso - */ - spi_config_t(edge_t edge = EDGE_RISE){ - mosi_edge = edge; - miso_edge = edge; - } -}; - /*! * The daughter board dboard interface to be subclassed. * A dboard instance interfaces with the mboard though this api. @@ -61,7 +34,6 @@ struct UHD_API spi_config_t{ class UHD_API dboard_iface{ public: typedef boost::shared_ptr sptr; - typedef std::vector byte_vector_t; //tells the host which unit to use enum unit_t{ diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 0fd2522cf..2a687f34f 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -243,3 +244,11 @@ io_type_t::io_type_t(size_t size) : size(size), tid(CUSTOM_TYPE){ /* NOP */ } + +/*********************************************************************** + * serial + **********************************************************************/ +spi_config_t::spi_config_t(edge_t edge){ + mosi_edge = edge; + miso_edge = edge; +} diff --git a/host/lib/usrp/usrp2/clock_control.cpp b/host/lib/usrp/usrp2/clock_control.cpp index dcd7ce9da..72f1f1c7a 100644 --- a/host/lib/usrp/usrp2/clock_control.cpp +++ b/host/lib/usrp/usrp2/clock_control.cpp @@ -21,6 +21,7 @@ #include "usrp2_regs.hpp" //spi slave constants #include +using namespace uhd; using namespace uhd::usrp; /*! diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 2859a7981..5ccb6fa47 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -17,7 +17,8 @@ #include "usrp2_iface.hpp" #include "clock_control.hpp" -#include "usrp2_regs.hpp" +#include "usrp2_regs.hpp" //wishbone address constants +#include #include #include #include @@ -25,6 +26,7 @@ #include #include +using namespace uhd; using namespace uhd::usrp; class usrp2_dboard_iface : public dboard_iface{ @@ -214,7 +216,7 @@ void usrp2_dboard_iface::write_i2c(int i2c_addr, const byte_vector_t &buf){ ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); } -dboard_iface::byte_vector_t usrp2_dboard_iface::read_i2c(int i2c_addr, size_t num_bytes){ +byte_vector_t usrp2_dboard_iface::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); diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 5c84fd8d3..742c53a14 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -24,7 +24,6 @@ #include using namespace uhd; -using namespace uhd::usrp; class usrp2_iface_impl : public usrp2_iface{ public: diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 1298d87f1..6667c8998 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -19,7 +19,7 @@ #define INCLUDED_USRP2_IFACE_HPP #include -#include //spi config +#include #include #include #include @@ -87,7 +87,7 @@ public: */ virtual boost::uint32_t transact_spi( int which_slave, - const uhd::usrp::spi_config_t &config, + const uhd::spi_config_t &config, boost::uint32_t data, size_t num_bits, bool readback -- cgit v1.2.3 From 6b015b1c517733e85cb0c08a379e8d20377bf2fa Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 19 Apr 2010 23:48:00 -0700 Subject: added comments to cmakelists, makedir in file generation script so python doesnt have to --- host/docs/CMakeLists.txt | 30 +++++++++++++++++++++++------- host/include/uhd/types/metadata.hpp | 10 ++++++++-- host/lib/CMakeLists.txt | 7 +++++++ host/lib/ic_reg_maps/common.py | 4 ---- host/lib/ic_reg_maps/gen_ad5624_regs.py | 2 -- host/lib/ic_reg_maps/gen_ad7922_regs.py | 2 -- host/lib/ic_reg_maps/gen_ad9510_regs.py | 2 -- host/lib/ic_reg_maps/gen_ad9777_regs.py | 2 -- host/lib/ic_reg_maps/gen_adf4360_regs.py | 2 -- 9 files changed, 38 insertions(+), 23 deletions(-) (limited to 'host/include') diff --git a/host/docs/CMakeLists.txt b/host/docs/CMakeLists.txt index 52376fe8c..476023a1e 100644 --- a/host/docs/CMakeLists.txt +++ b/host/docs/CMakeLists.txt @@ -35,25 +35,33 @@ IF(${RST2HTML} STREQUAL "RST2HTML-NOTFOUND") ELSE(${RST2HTML} STREQUAL "RST2HTML-NOTFOUND") MESSAGE(STATUS "Checking for rst2html (docutils) - found") MESSAGE(STATUS " Enabled generation of HTML manual.") - SET(stylesheet ${CMAKE_CURRENT_SOURCE_DIR}/style.css) + + #setup rst2html options SET(rst2html_options - --stylesheet=${stylesheet} - --no-toc-backlinks - --date - --time + --stylesheet=${CMAKE_CURRENT_SOURCE_DIR}/style.css + --no-toc-backlinks --date --time ) + + #create generation rule for each source FOREACH(rstfile ${manual_sources}) + #set input and output file names SET(rstfile ${CMAKE_CURRENT_SOURCE_DIR}/${rstfile}) GET_FILENAME_COMPONENT(rstfile_we ${rstfile} NAME_WE) SET(htmlfile ${CMAKE_CURRENT_BINARY_DIR}/${rstfile_we}.html) + + #make the html file depend on the rst file ADD_CUSTOM_COMMAND( OUTPUT ${htmlfile} DEPENDS ${rstfile} ${stylesheet} COMMAND ${RST2HTML} ${rstfile} ${htmlfile} ${rst2html_options} COMMENT "Generating ${htmlfile}" ) + + #make the manual target depend on the html file LIST(APPEND manual_html_files ${htmlfile}) INSTALL(FILES ${htmlfile} DESTINATION ${PKG_DOC_DIR}/manual/html) ENDFOREACH(rstfile ${manual_sources}) + + #make the html manual a build-time dependency ADD_CUSTOM_TARGET(manual_html ALL DEPENDS ${manual_html_files}) ENDIF(${RST2HTML} STREQUAL "RST2HTML-NOTFOUND") @@ -66,16 +74,24 @@ INCLUDE(FindDoxygen) IF(DOXYGEN_FOUND) MESSAGE(STATUS " Enabled generation of Doxygen documentation.") + + #generate the doxygen configuration file SET(CMAKE_CURRENT_BINARY_DIR_DOXYGEN ${CMAKE_CURRENT_BINARY_DIR}/doxygen) CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) - ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN} + + #make doxygen directory depend on the header files + FILE(GLOB_RECURSE header_files ${CMAKE_SOURCE_DIR}/include/*.hpp) + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN} DEPENDS ${header_files} COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating documentation with doxygen" ) - ADD_CUSTOM_TARGET(doxygen_html ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN}) + + #make the doxygen generation a built-time dependency + ADD_CUSTOM_TARGET(doxygen_docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN}) INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN} DESTINATION ${PKG_DOC_DIR}) ELSE(DOXYGEN_FOUND) MESSAGE(STATUS " Disabled generation of Doxygen documentation.") diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp index d93b38b50..55add71cc 100644 --- a/host/include/uhd/types/metadata.hpp +++ b/host/include/uhd/types/metadata.hpp @@ -70,7 +70,10 @@ namespace uhd{ * Timed-out on receive? */ - //default constructor + /*! + * The default constructor: + * Sets the fields to default values (flags set to false). + */ rx_metadata_t(void); }; @@ -103,7 +106,10 @@ namespace uhd{ bool start_of_burst; bool end_of_burst; - //default constructor + /*! + * The default constructor: + * Sets the fields to default values (flags set to false). + */ tx_metadata_t(void); }; diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 7b8149802..7cb74d30a 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -66,11 +66,18 @@ SET(libuhd_sources # Generate Files ######################################################################## MACRO(UHD_PYTHON_GEN_SOURCE_FILE pyfile outfile) + #ensure that the directory exists for outfile + GET_FILENAME_COMPONENT(outfile_dir ${outfile} PATH) + FILE(MAKE_DIRECTORY ${outfile_dir}) + + #make the outfile depend on the python script ADD_CUSTOM_COMMAND( OUTPUT ${outfile} DEPENDS ${pyfile} COMMAND ${PYTHON_EXECUTABLE} ${pyfile} ${outfile} COMMENT "Generating ${outfile}" ) + + #make libuhd depend on the outfile LIST(APPEND libuhd_sources ${outfile}) ENDMACRO(UHD_PYTHON_GEN_SOURCE_FILE) diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py index b7fa27bbe..bf51073ae 100644 --- a/host/lib/ic_reg_maps/common.py +++ b/host/lib/ic_reg_maps/common.py @@ -19,16 +19,12 @@ # Boston, MA 02110-1301, USA. import re -import os import math from Cheetah.Template import Template def parse_tmpl(_tmpl_text, **kwargs): return str(Template(_tmpl_text, kwargs)) -def safe_makedirs(path): - not os.path.isdir(path) and os.makedirs(path) - class reg: def __init__(self, reg_des): x = re.match('^(\w*)\s*(\w*)\[(.*)\]\s*(\w*)\s*(.*)$', reg_des) diff --git a/host/lib/ic_reg_maps/gen_ad5624_regs.py b/host/lib/ic_reg_maps/gen_ad5624_regs.py index 378a6912f..a809d2f47 100755 --- a/host/lib/ic_reg_maps/gen_ad5624_regs.py +++ b/host/lib/ic_reg_maps/gen_ad5624_regs.py @@ -19,7 +19,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -import os import sys from common import * @@ -83,5 +82,4 @@ struct ad5624_regs_t{ if __name__ == '__main__': regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) diff --git a/host/lib/ic_reg_maps/gen_ad7922_regs.py b/host/lib/ic_reg_maps/gen_ad7922_regs.py index e1e67d617..512dcdc46 100755 --- a/host/lib/ic_reg_maps/gen_ad7922_regs.py +++ b/host/lib/ic_reg_maps/gen_ad7922_regs.py @@ -19,7 +19,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -import os import sys from common import * @@ -89,5 +88,4 @@ struct ad7922_regs_t{ if __name__ == '__main__': regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) diff --git a/host/lib/ic_reg_maps/gen_ad9510_regs.py b/host/lib/ic_reg_maps/gen_ad9510_regs.py index 32a8a04c6..4f28d5597 100755 --- a/host/lib/ic_reg_maps/gen_ad9510_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9510_regs.py @@ -19,7 +19,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -import os import sys from common import * @@ -174,5 +173,4 @@ struct ad9510_regs_t{ if __name__ == '__main__': regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) diff --git a/host/lib/ic_reg_maps/gen_ad9777_regs.py b/host/lib/ic_reg_maps/gen_ad9777_regs.py index e4369291a..65a9657a4 100755 --- a/host/lib/ic_reg_maps/gen_ad9777_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9777_regs.py @@ -19,7 +19,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -import os import sys from common import * @@ -152,5 +151,4 @@ struct ad9777_regs_t{ if __name__ == '__main__': regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) diff --git a/host/lib/ic_reg_maps/gen_adf4360_regs.py b/host/lib/ic_reg_maps/gen_adf4360_regs.py index f82e8c7c5..c659766dc 100755 --- a/host/lib/ic_reg_maps/gen_adf4360_regs.py +++ b/host/lib/ic_reg_maps/gen_adf4360_regs.py @@ -19,7 +19,6 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -import os import sys from common import * @@ -123,5 +122,4 @@ struct adf4360_regs_t{ if __name__ == '__main__': regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) -- cgit v1.2.3 From eae0bec99bca5efa1e86faa03132ec5e8aca5fe5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 20 Apr 2010 12:05:33 -0700 Subject: Created args string contructor for device address. Using the args string for the find devices app. Added documentation to simple usrp. --- host/examples/rx_timed_samples.cpp | 9 +++---- host/include/uhd/types/device_addr.hpp | 20 ++++++++------- host/include/uhd/usrp/simple_usrp.hpp | 47 +++++++++++++++++++++++++++++++++- host/lib/types.cpp | 46 ++++++++++++++++----------------- host/lib/usrp/simple_usrp.cpp | 39 +++++++++++++++++++++------- host/test/addr_test.cpp | 2 +- host/utils/uhd_find_devices.cpp | 14 ++-------- 7 files changed, 116 insertions(+), 61 deletions(-) (limited to 'host/include') diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index d49f7d182..4b8774036 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -26,7 +26,7 @@ namespace po = boost::program_options; int UHD_SAFE_MAIN(int argc, char *argv[]){ //variables to be set by po - std::string transport_args; + std::string args; int seconds_in_future; size_t total_num_samps; double rx_rate; @@ -35,7 +35,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") - ("args", po::value(&transport_args)->default_value(""), "simple uhd transport args") + ("args", po::value(&args)->default_value(""), "simple uhd device address args") ("secs", po::value(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") ("nsamps", po::value(&total_num_samps)->default_value(1000), "total number of samples to receive") ("rxrate", po::value(&rx_rate)->default_value(100e6/16), "rate of incoming samples") @@ -52,9 +52,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //create a usrp device std::cout << std::endl; - std::cout << boost::format("Creating the usrp device with: %s...") - % transport_args << std::endl; - uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(transport_args); + std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; + uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(args); uhd::device::sptr dev = sdev->get_device(); std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp index f5dd9371c..e8da2a1ab 100644 --- a/host/include/uhd/types/device_addr.hpp +++ b/host/include/uhd/types/device_addr.hpp @@ -32,13 +32,23 @@ namespace uhd{ * * To narrow down the discovery process to a particular device, * specify a transport key/value pair specific to your device. - * Ex, to find a usrp2: my_dev_addr["addr"] = [resolvable_hostname_or_ip] + * - Ex, to find a usrp2: my_dev_addr["addr"] = [resolvable_hostname_or_ip] * * The device address can also be used to pass arguments into * the transport layer control to set (for example) buffer sizes. + * + * An arguments string, is a way to represent a device address + * using a single string with delimiter characters. + * - Ex: addr=192.168.10.2 + * - Ex: addr=192.168.10.2, rx_buff_size=1e6 */ class UHD_API device_addr_t : public dict{ public: + /*! + * Create a device address from an args string. + * \param args the arguments string + */ + device_addr_t(const std::string &args = ""); /*! * Convert a device address into a printable string. @@ -52,14 +62,6 @@ namespace uhd{ * \return a string with delimiter markup */ std::string to_args_str(void) const; - - /*! - * Make a device address from an args string. - * The args string contains delimiter symbols. - * \param args_str the arguments string - * \return the new device address - */ - static device_addr_t from_args_str(const std::string &args_str); }; //handy typedef for a vector of device addresses diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index c4e0338f7..e3f181ec3 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -39,18 +39,63 @@ namespace uhd{ namespace usrp{ class UHD_API simple_usrp : boost::noncopyable{ public: typedef boost::shared_ptr sptr; - static sptr make(const std::string &args); + /*! + * Make a new simple usrp from the device address. + * \param dev_addr the device address + * \return a new simple usrp object + */ + static sptr make(const device_addr_t &dev_addr); + + /*! + * Get the underlying device object. + * This is needed to get access to the streaming API and properties. + * \return the device object within this simple usrp + */ virtual device::sptr get_device(void) = 0; + /*! + * Get a printable name for this simple usrp. + * \return a printable string + */ virtual std::string get_name(void) = 0; /******************************************************************* * Misc ******************************************************************/ + /*! + * Sets the time registers on the usrp immediately. + * \param time_spec the time to latch into the usrp device + */ virtual void set_time_now(const time_spec_t &time_spec) = 0; + + /*! + * Set the time registers on the usrp at the next pps tick. + * The values will not be latched in until the pulse occurs. + * It is recommended that the user sleep(1) after calling to ensure + * that the time registers will be in a known state prior to use. + * + * Note: Because this call sets the time on the "next" pps, + * the seconds in the time spec should be current seconds + 1. + * + * \param time_spec the time to latch into the usrp device + */ virtual void set_time_next_pps(const time_spec_t &time_spec) = 0; + + /*! + * Issue a stream command to the usrp device. + * This tells the usrp to send samples into the host. + * See the documentation for stream_cmd_t for more info. + * \param stream_cmd the stream command to issue + */ virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0; + + /*! + * Set the clock configuration for the usrp device. + * This tells the usrp how to get a 10Mhz reference and PPS clock. + * See the documentation for clock_config_t for more info. + * \param clock_config the clock configuration to set + */ virtual void set_clock_config(const clock_config_t &clock_config) = 0; /******************************************************************* diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 2a687f34f..91887840c 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -119,46 +119,44 @@ void time_spec_t::set_ticks(boost::uint32_t ticks, double tick_rate){ /*********************************************************************** * device addr **********************************************************************/ -std::string device_addr_t::to_string(void) const{ - std::stringstream ss; - BOOST_FOREACH(std::string key, this->keys()){ - ss << boost::format("%s: %s") % key % (*this)[key] << std::endl; - } - return ss.str(); -} - -static const std::string arg_delim = ";"; +static const std::string arg_delim = ","; static const std::string pair_delim = "="; static std::string trim(const std::string &in){ return boost::algorithm::trim_copy(in); } -std::string device_addr_t::to_args_str(void) const{ - std::string args_str; - BOOST_FOREACH(const std::string &key, this->keys()){ - args_str += key + pair_delim + (*this)[key] + arg_delim; - } - return args_str; -} - -device_addr_t device_addr_t::from_args_str(const std::string &args_str){ - device_addr_t addr; - +device_addr_t::device_addr_t(const std::string &args){ //split the args at the semi-colons std::vector pairs; - boost::split(pairs, args_str, boost::is_any_of(arg_delim)); + boost::split(pairs, args, boost::is_any_of(arg_delim)); BOOST_FOREACH(const std::string &pair, pairs){ if (trim(pair) == "") continue; //split the key value pairs at the equals std::vector key_val; boost::split(key_val, pair, boost::is_any_of(pair_delim)); - if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args_str); - addr[trim(key_val[0])] = trim(key_val[1]); + if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); + (*this)[trim(key_val[0])] = trim(key_val[1]); } +} + +std::string device_addr_t::to_string(void) const{ + if (this->size() == 0) return "Empty Device Address"; + + std::stringstream ss; + BOOST_FOREACH(std::string key, this->keys()){ + ss << boost::format("%s: %s") % key % (*this)[key] << std::endl; + } + return ss.str(); +} - return addr; +std::string device_addr_t::to_args_str(void) const{ + std::string args_str; + BOOST_FOREACH(const std::string &key, this->keys()){ + args_str += key + pair_delim + (*this)[key] + arg_delim; + } + return args_str; } /*********************************************************************** diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index 11ee3a798..321d66a4a 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -42,14 +42,14 @@ public: _tx_dsp = _mboard[MBOARD_PROP_TX_DSP]; //extract rx subdevice - wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD]; - std::string rx_subdev_in_use = rx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); - _rx_subdev = rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)]; + _rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD]; + std::string rx_subdev_in_use = _rx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _rx_subdev = _rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)]; //extract tx subdevice - wax::obj tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD]; - std::string tx_subdev_in_use = tx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); - _tx_subdev = tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]; + _tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD]; + std::string tx_subdev_in_use = _tx_dboard[DBOARD_PROP_USED_SUBDEVS].as().at(0); + _tx_subdev = _tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]; } ~simple_usrp_impl(void){ @@ -61,7 +61,26 @@ public: } std::string get_name(void){ - return _mboard[MBOARD_PROP_NAME].as(); + return str(boost::format( + "Simple USRP:\n" + " Device: %s\n" + " Mboard: %s\n" + " RX DSP: %s\n" + " RX Dboard: %s\n" + " RX Subdev: %s\n" + " TX DSP: %s\n" + " TX Dboard: %s\n" + " TX Subdev: %s\n" + ) + % (*_dev)[DEVICE_PROP_NAME].as() + % _mboard[MBOARD_PROP_NAME].as() + % _rx_dsp[DSP_PROP_NAME].as() + % _rx_dboard[DBOARD_PROP_NAME].as() + % _rx_subdev[SUBDEV_PROP_NAME].as() + % _tx_dsp[DSP_PROP_NAME].as() + % _tx_dboard[DBOARD_PROP_NAME].as() + % _tx_subdev[SUBDEV_PROP_NAME].as() + ); } /******************************************************************* @@ -174,6 +193,8 @@ private: wax::obj _mboard; wax::obj _rx_dsp; wax::obj _tx_dsp; + wax::obj _rx_dboard; + wax::obj _tx_dboard; wax::obj _rx_subdev; wax::obj _tx_subdev; }; @@ -181,6 +202,6 @@ private: /*********************************************************************** * The Make Function **********************************************************************/ -simple_usrp::sptr simple_usrp::make(const std::string &args){ - return sptr(new simple_usrp_impl(device_addr_t::from_args_str(args))); +simple_usrp::sptr simple_usrp::make(const device_addr_t &dev_addr){ + return sptr(new simple_usrp_impl(dev_addr)); } diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp index 2ec6de14b..93b7cc0df 100644 --- a/host/test/addr_test.cpp +++ b/host/test/addr_test.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(test_device_addr){ std::cout << "Pretty Print: " << std::endl << dev_addr.to_string(); std::string args_str = dev_addr.to_args_str(); std::cout << "Args String: " << args_str << std::endl; - uhd::device_addr_t new_dev_addr = uhd::device_addr_t::from_args_str(args_str); + uhd::device_addr_t new_dev_addr(args_str); //they should be the same size BOOST_CHECK_EQUAL(dev_addr.size(), new_dev_addr.size()); diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp index 6c945cbca..8222dc1f4 100644 --- a/host/utils/uhd_find_devices.cpp +++ b/host/utils/uhd_find_devices.cpp @@ -27,8 +27,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("node", po::value(), "path to linux device node") + ("args", po::value()->default_value(""), "device address args") ; po::variables_map vm; @@ -41,17 +40,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ return ~0; } - //load the options into the address - uhd::device_addr_t device_addr; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - if (vm.count("node")){ - device_addr["node"] = vm["node"].as(); - } - //discover the usrps and print the results - uhd::device_addrs_t device_addrs = uhd::device::find(device_addr); + uhd::device_addrs_t device_addrs = uhd::device::find(vm["args"].as()); if (device_addrs.size() == 0){ std::cerr << "No UHD Devices Found" << std::endl; -- cgit v1.2.3 From 039eceb4b208b2ca5a3465d2f16c8d5a7c7276c7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 23 Apr 2010 19:21:47 -0700 Subject: Moved reading the eeprom (dboard ids) onto the host. Created a eeprom parser for the format in the dboard. Removed the support from the microblaze code. --- firmware/microblaze/apps/txrx.c | 16 ------- firmware/microblaze/lib/Makefile.am | 2 - firmware/microblaze/lib/db.h | 31 ------------- firmware/microblaze/lib/db_init.c | 77 -------------------------------- firmware/microblaze/lib/u2_init.c | 1 - host/include/uhd/usrp/CMakeLists.txt | 1 + host/include/uhd/usrp/dboard_eeprom.hpp | 55 +++++++++++++++++++++++ host/lib/CMakeLists.txt | 1 + host/lib/usrp/dboard_eeprom.cpp | 78 +++++++++++++++++++++++++++++++++ host/lib/usrp/usrp2/dboard_iface.cpp | 36 +-------------- host/lib/usrp/usrp2/dboard_impl.cpp | 15 +++---- host/lib/usrp/usrp2/fw_common.h | 17 +------ host/lib/usrp/usrp2/usrp2_iface.cpp | 61 ++++++++++++++++++++++++++ host/lib/usrp/usrp2/usrp2_iface.hpp | 55 +++++++++++++++++++++++ 14 files changed, 259 insertions(+), 187 deletions(-) delete mode 100644 firmware/microblaze/lib/db.h delete mode 100644 firmware/microblaze/lib/db_init.c create mode 100644 host/include/uhd/usrp/dboard_eeprom.hpp create mode 100644 host/lib/usrp/dboard_eeprom.cpp (limited to 'host/include') diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 7a6fbd993..8ff3b8c58 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -45,7 +45,6 @@ #include "clocks.h" #include #include "usrp2/fw_common.h" -#include #include #include #include @@ -257,12 +256,6 @@ void handle_udp_ctrl_packet( memcpy(&ctrl_data_out.data.mac_addr, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); break; - case USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO: - ctrl_data_out.id = USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE; - ctrl_data_out.data.dboard_ids.tx_id = read_dboard_eeprom(I2C_ADDR_TX_A); - ctrl_data_out.data.dboard_ids.rx_id = read_dboard_eeprom(I2C_ADDR_RX_A); - break; - /******************************************************************* * SPI ******************************************************************/ @@ -418,15 +411,6 @@ void handle_udp_ctrl_packet( ctrl_data_out.id = USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE; break; - /******************************************************************* - * Hardware Rev Numbers - ******************************************************************/ - case USRP2_CTRL_ID_WHATS_THE_HARDWARE_REV_NOS_BRO: - ctrl_data_out.data.hw_rev.major = u2_hw_rev_major; - ctrl_data_out.data.hw_rev.minor = u2_hw_rev_minor; - ctrl_data_out.id = USRP2_CTRL_ID_TAKE_THE_HARDWARE_REV_NOS_DUDE; - break; - default: ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT; diff --git a/firmware/microblaze/lib/Makefile.am b/firmware/microblaze/lib/Makefile.am index bd8972f5c..783895850 100644 --- a/firmware/microblaze/lib/Makefile.am +++ b/firmware/microblaze/lib/Makefile.am @@ -28,7 +28,6 @@ libu2fw_a_SOURCES = \ bsm12.c \ buffer_pool.c \ clocks.c \ - db_init.c \ dbsm.c \ eeprom.c \ ethernet.c \ @@ -60,7 +59,6 @@ noinst_HEADERS = \ bsm12.h \ buffer_pool.h \ clocks.h \ - db.h \ dbsm.h \ eth_mac.h \ eth_mac_regs.h \ diff --git a/firmware/microblaze/lib/db.h b/firmware/microblaze/lib/db.h deleted file mode 100644 index 358cb222b..000000000 --- a/firmware/microblaze/lib/db.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008,2009 Free Software Foundation, Inc. - * - * 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 . - */ - -/* - * Interface to daughterboard code - */ - -#ifndef INCLUDED_DB_H -#define INCLUDED_DB_H - -#include -#include - -int read_dboard_eeprom(int i2c_addr); - -#endif /* INCLUDED_DB_H */ diff --git a/firmware/microblaze/lib/db_init.c b/firmware/microblaze/lib/db_init.c deleted file mode 100644 index 23805d9cd..000000000 --- a/firmware/microblaze/lib/db_init.c +++ /dev/null @@ -1,77 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -/* - * Copyright 2008,2009 Free Software Foundation, Inc. - * - * 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 - - -typedef enum { UDBE_OK, UDBE_NO_EEPROM, UDBE_INVALID_EEPROM } usrp_dbeeprom_status_t; - -static usrp_dbeeprom_status_t -read_raw_dboard_eeprom (unsigned char *buf, int i2c_addr) -{ - if (!eeprom_read (i2c_addr, 0, buf, DB_EEPROM_CLEN)) - return UDBE_NO_EEPROM; - - if (buf[DB_EEPROM_MAGIC] != DB_EEPROM_MAGIC_VALUE) - return UDBE_INVALID_EEPROM; - - int sum = 0; - unsigned int i; - for (i = 0; i < DB_EEPROM_CLEN; i++) - sum += buf[i]; - - if ((sum & 0xff) != 0) - return UDBE_INVALID_EEPROM; - - return UDBE_OK; -} - - -/* - * Return DBID, -1 or -2 - */ -int -read_dboard_eeprom(int i2c_addr) -{ - unsigned char buf[DB_EEPROM_CLEN]; - - usrp_dbeeprom_status_t s = read_raw_dboard_eeprom (buf, i2c_addr); - - //printf("\nread_raw_dboard_eeprom: %d\n", s); - - switch (s){ - case UDBE_OK: - return (buf[DB_EEPROM_ID_MSB] << 8) | buf[DB_EEPROM_ID_LSB]; - - case UDBE_NO_EEPROM: - default: - return -1; - - case UDBE_INVALID_EEPROM: - return -2; - } -} diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 76e83c660..399d834cb 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -25,7 +25,6 @@ #include "i2c.h" #include "mdelay.h" #include "clocks.h" -#include "db.h" #include "usrp2_i2c_addr.h" //#include "nonstdio.h" diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index 23758041c..bbd124ed8 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES #### dboard headers ### dboard_base.hpp + dboard_eeprom.hpp dboard_id.hpp dboard_iface.hpp dboard_manager.hpp diff --git a/host/include/uhd/usrp/dboard_eeprom.hpp b/host/include/uhd/usrp/dboard_eeprom.hpp new file mode 100644 index 000000000..6be88c85a --- /dev/null +++ b/host/include/uhd/usrp/dboard_eeprom.hpp @@ -0,0 +1,55 @@ +// +// 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_UHD_USRP_DBOARD_EEPROM_HPP +#define INCLUDED_UHD_USRP_DBOARD_EEPROM_HPP + +#include +#include +#include +#include + +namespace uhd{ namespace usrp{ + +struct UHD_API dboard_eeprom_t{ + /*! + * The dboard id that was read from eeprom or will be set to eeprom. + */ + dboard_id_t id; + + /*! + * Create a dboard eeprom struct from the bytes read out of eeprom + * \param buf the vector of bytes + */ + dboard_eeprom_t(const uhd::byte_vector_t &buf = uhd::byte_vector_t(0)); + + /*! + * Get the bytes that would be written to dboard eeprom + * \return a vector of bytes + */ + uhd::byte_vector_t get_eeprom_bytes(void); + + /*! + * Get the number of bytes to read out of eeprom. + * \return the number of bytes we are interested in + */ + static size_t num_bytes(void); +}; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_DBOARD_EEPROM_HPP */ diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 5495620ec..ffbf15484 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -55,6 +55,7 @@ SET(libuhd_sources transport/if_addrs.cpp transport/udp_simple.cpp usrp/dboard_base.cpp + usrp/dboard_eeprom.cpp usrp/simple_usrp.cpp usrp/dboard_manager.cpp usrp/tune_helper.cpp diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp new file mode 100644 index 000000000..a8fac602a --- /dev/null +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -0,0 +1,78 @@ +// +// 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; +using namespace uhd::usrp; + +//////////////////////////////////////////////////////////////////////// +// format of daughterboard EEPROM +// 00: 0xDB code for ``I'm a daughterboard'' +// 01: .. Daughterboard ID (LSB) +// 02: .. Daughterboard ID (MSB) +// 03: .. io bits 7-0 direction (bit set if it's an output from m'board) +// 04: .. io bits 15-8 direction (bit set if it's an output from m'board) +// 05: .. ADC0 DC offset correction (LSB) +// 06: .. ADC0 DC offset correction (MSB) +// 07: .. ADC1 DC offset correction (LSB) +// 08: .. ADC1 DC offset correction (MSB) +// ... +// 1f: .. negative of the sum of bytes [0x00, 0x1e] + +#define DB_EEPROM_MAGIC 0x00 +#define DB_EEPROM_MAGIC_VALUE 0xDB +#define DB_EEPROM_ID_LSB 0x01 +#define DB_EEPROM_ID_MSB 0x02 +#define DB_EEPROM_OE_LSB 0x03 +#define DB_EEPROM_OE_MSB 0x04 +#define DB_EEPROM_OFFSET_0_LSB 0x05 // offset correction for ADC or DAC 0 +#define DB_EEPROM_OFFSET_0_MSB 0x06 +#define DB_EEPROM_OFFSET_1_LSB 0x07 // offset correction for ADC or DAC 1 +#define DB_EEPROM_OFFSET_1_MSB 0x08 +#define DB_EEPROM_CHKSUM 0x1f + +#define DB_EEPROM_CLEN 0x20 // length of common portion of eeprom + +#define DB_EEPROM_CUSTOM_BASE DB_EEPROM_CLEN // first avail offset for + // daughterboard specific use +//////////////////////////////////////////////////////////////////////// + +dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &buf){ + try{ + ASSERT_THROW(buf.size() >= num_bytes()); + ASSERT_THROW(buf[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + id = \ + (boost::uint16_t(buf[DB_EEPROM_ID_LSB]) << 0) | + (boost::uint16_t(buf[DB_EEPROM_ID_MSB]) << 8) ; + }catch(const uhd::assert_error &e){ + id = dboard_id::NONE; + } +} + +byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ + byte_vector_t bytes(3); + bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; + bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0); + bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8); + return bytes; +} + +size_t dboard_eeprom_t::num_bytes(void){ + return 3; +} diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index e9acddee6..9d9b745ae 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -24,7 +24,6 @@ #include #include //htonl and ntohl #include -#include #include "ad7922_regs.hpp" //aux adc #include "ad5624_regs.hpp" //aux dac @@ -214,42 +213,11 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi( * I2C **********************************************************************/ void usrp2_dboard_iface::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 - std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data); - - //send and recv - usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); + return _iface->write_i2c(i2c_addr, buf); } byte_vector_t usrp2_dboard_iface::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 = _iface->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(num_bytes); - std::copy(in_data.data.i2c_args.data, in_data.data.i2c_args.data + num_bytes, result.begin()); - return result; + return _iface->read_i2c(i2c_addr, num_bytes); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index ee23dc83a..d697f11f0 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -18,6 +18,7 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" +#include #include #include #include @@ -33,22 +34,16 @@ 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 = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE); - - //extract the dboard ids an convert them - dboard_id_t rx_dboard_id = ntohs(in_data.data.dboard_ids.rx_id); - dboard_id_t tx_dboard_id = ntohs(in_data.data.dboard_ids.tx_id); + //extract the dboard ids + dboard_eeprom_t db_rx_eeprom(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); + dboard_eeprom_t db_tx_eeprom(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); //create a new dboard interface and manager dboard_iface::sptr _dboard_iface( make_usrp2_dboard_iface(_iface, _clk_ctrl) ); _dboard_manager = dboard_manager::make( - rx_dboard_id, tx_dboard_id, _dboard_iface + db_rx_eeprom.id, db_tx_eeprom.id, _dboard_iface ); //load dboards diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 640b37ec6..e80001ff2 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -34,7 +34,7 @@ extern "C" { //defines the protocol version in this shared header //increment this value when the protocol is changed -#define USRP2_PROTO_VERSION 1 +#define USRP2_PROTO_VERSION 2 //used to differentiate control packets over data port #define USRP2_INVALID_VRT_HEADER 0 @@ -61,9 +61,6 @@ typedef enum{ USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE = 'M', USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO = 'n', - USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO = 'd', - USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE = 'D', - USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's', USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S', @@ -82,9 +79,6 @@ typedef enum{ USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r', USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R', - USRP2_CTRL_ID_WHATS_THE_HARDWARE_REV_NOS_BRO = 'y', - USRP2_CTRL_ID_TAKE_THE_HARDWARE_REV_NOS_DUDE = 'Y', - USRP2_CTRL_ID_PEACE_OUT = '~' } usrp2_ctrl_id_t; @@ -106,10 +100,6 @@ typedef struct{ union{ _SINS_ uint32_t ip_addr; _SINS_ uint8_t mac_addr[6]; - struct { - _SINS_ uint16_t rx_id; - _SINS_ uint16_t tx_id; - } dboard_ids; struct { _SINS_ uint8_t dev; _SINS_ uint8_t miso_edge; @@ -137,11 +127,6 @@ typedef struct{ _SINS_ uint32_t data; _SINS_ uint8_t num_bytes; //1, 2, 4 } poke_args; - struct { - _SINS_ uint8_t major; - _SINS_ uint8_t minor; - _SINS_ uint8_t _pad[2]; - } hw_rev; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 1b0dde1b4..c639c0dfe 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -19,9 +19,11 @@ #include #include #include +#include #include //used for htonl and ntohl #include #include +#include using namespace uhd; @@ -89,6 +91,65 @@ public: return ntohl(out_data.data.spi_args.data); } +/*********************************************************************** + * I2C + **********************************************************************/ + void write_i2c(boost::uint8_t 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 = 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 + std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); + } + + byte_vector_t read_i2c(boost::uint8_t 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 = 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 = this->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(num_bytes); + std::copy(in_data.data.i2c_args.data, in_data.data.i2c_args.data + num_bytes, result.begin()); + return result; + } + +/*********************************************************************** + * EEPROM + **********************************************************************/ + void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &buf){ + BOOST_FOREACH(boost::uint8_t byte, buf){ + //write a byte at a time, its easy that way + byte_vector_t cmd = boost::assign::list_of(offset)(byte); + this->write_i2c(addr, cmd); + } + } + + byte_vector_t read_eeprom(boost::uint8_t addr, boost::uint8_t offset, size_t num_bytes){ + //do a zero byte write to start read cycle + write_i2c(addr, byte_vector_t(1, offset)); + return read_i2c(addr, num_bytes); + } + /*********************************************************************** * Send/Recv over control **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 6667c8998..938359677 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -25,6 +25,15 @@ #include #include "fw_common.h" +//////////////////////////////////////////////////////////////////////// +// I2C addresses +//////////////////////////////////////////////////////////////////////// +#define I2C_DEV_EEPROM 0x50 // 24LC02[45]: 7-bits 1010xxx +#define I2C_ADDR_MBOARD (I2C_DEV_EEPROM | 0x0) +#define I2C_ADDR_TX_DB (I2C_DEV_EEPROM | 0x4) +#define I2C_ADDR_RX_DB (I2C_DEV_EEPROM | 0x5) +//////////////////////////////////////////////////////////////////////// + /*! * The usrp2 interface class: * Provides a set of functions to implementation layer. @@ -93,6 +102,52 @@ public: bool readback ) = 0; + /*! + * Write bytes over the i2c. + * \param addr the address + * \param buf the vector of bytes + */ + virtual void write_i2c( + boost::uint8_t addr, + const uhd::byte_vector_t &buf + ) = 0; + + /*! + * Read bytes over the i2c. + * \param addr the address + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual uhd::byte_vector_t read_i2c( + boost::uint8_t addr, + size_t num_bytes + ) = 0; + + /*! + * Write bytes to an eeprom. + * \param addr the address + * \param offset byte offset + * \param buf the vector of bytes + */ + virtual void write_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + const uhd::byte_vector_t &buf + ) = 0; + + /*! + * Read bytes from an eeprom. + * \param addr the address + * \param offset byte offset + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual uhd::byte_vector_t read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes + ) = 0; + /*! * Get the master clock frequency. * \return the frequency in Hz -- cgit v1.2.3 From 300ddf7807e5dd7662b09023ab80da26dd878626 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 24 Apr 2010 10:46:12 -0700 Subject: set dboard eeprom from dboard properties --- host/include/uhd/usrp/dboard_eeprom.hpp | 17 ++++++++----- host/include/uhd/usrp/dboard_iface.hpp | 10 ++++---- host/include/uhd/usrp/dboard_manager.hpp | 1 - host/include/uhd/usrp/dboard_props.hpp | 3 ++- host/lib/usrp/dboard_eeprom.cpp | 25 +++++++++++++------ host/lib/usrp/usrp2/dboard_iface.cpp | 12 +++++----- host/lib/usrp/usrp2/dboard_impl.cpp | 41 +++++++++++++++++++++++--------- host/lib/usrp/usrp2/usrp2_iface.cpp | 14 +++++++---- host/lib/usrp/usrp2/usrp2_impl.hpp | 3 +++ 9 files changed, 84 insertions(+), 42 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/usrp/dboard_eeprom.hpp b/host/include/uhd/usrp/dboard_eeprom.hpp index 6be88c85a..108027b46 100644 --- a/host/include/uhd/usrp/dboard_eeprom.hpp +++ b/host/include/uhd/usrp/dboard_eeprom.hpp @@ -32,20 +32,25 @@ struct UHD_API dboard_eeprom_t{ dboard_id_t id; /*! - * Create a dboard eeprom struct from the bytes read out of eeprom - * \param buf the vector of bytes + * Create a dboard eeprom struct from the bytes read out of eeprom. + * The constructor will parse out the dboard id from a vector of bytes. + * To be valid, the bytes vector should be at least num_bytes() long. + * If the parsing fails due to bad checksum or incomplete length, + * the dboard id in this struct will be set to dboard_id::NONE. + * \param bytes the vector of bytes */ - dboard_eeprom_t(const uhd::byte_vector_t &buf = uhd::byte_vector_t(0)); + dboard_eeprom_t(const uhd::byte_vector_t &bytes = uhd::byte_vector_t(0)); /*! - * Get the bytes that would be written to dboard eeprom + * Get the bytes that would be written to dboard eeprom. * \return a vector of bytes */ uhd::byte_vector_t get_eeprom_bytes(void); /*! - * Get the number of bytes to read out of eeprom. - * \return the number of bytes we are interested in + * Get the number of bytes in the dboard eeprom segment. + * Use this value when reading out of the dboard eeprom. + * \return the number of bytes used by dboard eeprom */ static size_t num_bytes(void); }; diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index 79b8ee664..1214a1a2f 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -95,19 +95,19 @@ public: /*! * Write to an I2C peripheral. * - * \param i2c_addr I2C bus address (7-bits) - * \param buf the data to write + * \param addr I2C bus address (7-bits) + * \param bytes the data to write */ - virtual void write_i2c(int i2c_addr, const byte_vector_t &buf) = 0; + virtual void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes) = 0; /*! * Read from an I2C peripheral. * - * \param i2c_addr I2C bus address (7-bits) + * \param addr I2C bus address (7-bits) * \param num_bytes number of bytes to read * \return the data read if successful, else a zero length string. */ - virtual byte_vector_t read_i2c(int i2c_addr, size_t num_bytes) = 0; + virtual byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes) = 0; /*! * Write data to SPI bus peripheral. diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index 6de64b02d..007d85bb4 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -33,7 +33,6 @@ namespace uhd{ namespace usrp{ * Provide wax::obj access to the subdevs inside. */ class UHD_API dboard_manager : boost::noncopyable{ - public: typedef boost::shared_ptr sptr; diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp index 3b290319f..0208a6c2c 100644 --- a/host/include/uhd/usrp/dboard_props.hpp +++ b/host/include/uhd/usrp/dboard_props.hpp @@ -29,7 +29,8 @@ namespace uhd{ namespace usrp{ DBOARD_PROP_NAME = 'n', //ro, std::string DBOARD_PROP_SUBDEV = 's', //ro, wax::obj DBOARD_PROP_SUBDEV_NAMES = 'S', //ro, prop_names_t - DBOARD_PROP_USED_SUBDEVS = 'u' //ro, prop_names_t + DBOARD_PROP_USED_SUBDEVS = 'u', //ro, prop_names_t + DBOARD_PROP_DBOARD_ID = 'i' //rw, dboard_id_t //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet }; diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index a8fac602a..5ce0b2328 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -53,26 +53,37 @@ using namespace uhd::usrp; // daughterboard specific use //////////////////////////////////////////////////////////////////////// -dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &buf){ +//negative sum of bytes excluding checksum byte +static boost::uint8_t checksum(const byte_vector_t &bytes){ + int sum; + for (size_t i = 0; i < DB_EEPROM_CHKSUM; i++){ + sum += int(bytes.at(i)); + } + return (-sum) & 0xff; +} + +dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ try{ - ASSERT_THROW(buf.size() >= num_bytes()); - ASSERT_THROW(buf[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); + ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); id = \ - (boost::uint16_t(buf[DB_EEPROM_ID_LSB]) << 0) | - (boost::uint16_t(buf[DB_EEPROM_ID_MSB]) << 8) ; + (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) | + (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ; }catch(const uhd::assert_error &e){ id = dboard_id::NONE; } } byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ - byte_vector_t bytes(3); + byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0); bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8); + bytes[DB_EEPROM_CHKSUM] = checksum(bytes); return bytes; } size_t dboard_eeprom_t::num_bytes(void){ - return 3; + return DB_EEPROM_CLEN; } diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 9d9b745ae..9503c329b 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -42,8 +42,8 @@ public: void set_gpio_ddr(unit_t, boost::uint16_t); boost::uint16_t read_gpio(unit_t); - void write_i2c(int, const byte_vector_t &); - byte_vector_t read_i2c(int, size_t); + void write_i2c(boost::uint8_t, const byte_vector_t &); + byte_vector_t read_i2c(boost::uint8_t, size_t); double get_clock_rate(unit_t); void set_clock_enabled(unit_t, bool); @@ -212,12 +212,12 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi( /*********************************************************************** * I2C **********************************************************************/ -void usrp2_dboard_iface::write_i2c(int i2c_addr, const byte_vector_t &buf){ - return _iface->write_i2c(i2c_addr, buf); +void usrp2_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){ + return _iface->write_i2c(addr, bytes); } -byte_vector_t usrp2_dboard_iface::read_i2c(int i2c_addr, size_t num_bytes){ - return _iface->read_i2c(i2c_addr, num_bytes); +byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){ + return _iface->read_i2c(addr, num_bytes); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index d697f11f0..8952a9f75 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -18,7 +18,6 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" -#include #include #include #include @@ -34,16 +33,16 @@ using namespace uhd::usrp; * Helper Methods **********************************************************************/ void usrp2_impl::dboard_init(void){ - //extract the dboard ids - dboard_eeprom_t db_rx_eeprom(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); - dboard_eeprom_t db_tx_eeprom(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); + //read the dboard eeprom to extract the dboard ids + _rx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); + _tx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); //create a new dboard interface and manager dboard_iface::sptr _dboard_iface( make_usrp2_dboard_iface(_iface, _clk_ctrl) ); _dboard_manager = dboard_manager::make( - db_rx_eeprom.id, db_tx_eeprom.id, _dboard_iface + _rx_db_eeprom.id, _tx_db_eeprom.id, _dboard_iface ); //load dboards @@ -120,19 +119,29 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _rx_subdevs_in_use; return; + case DBOARD_PROP_DBOARD_ID: + val = _rx_db_eeprom.id; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ - if (key.as() == DBOARD_PROP_USED_SUBDEVS){ + switch(key.as()){ + case DBOARD_PROP_USED_SUBDEVS: _rx_subdevs_in_use = val.as(); update_rx_mux_config(); //if the val is bad, this will throw return; - } - throw std::runtime_error("Cannot set on usrp2 dboard"); + case DBOARD_PROP_DBOARD_ID: + _rx_db_eeprom.id = val.as(); + _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + return; + + default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + } } /*********************************************************************** @@ -160,17 +169,27 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _tx_subdevs_in_use; return; + case DBOARD_PROP_DBOARD_ID: + val = _tx_db_eeprom.id; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ - if (key.as() == DBOARD_PROP_USED_SUBDEVS){ + switch(key.as()){ + case DBOARD_PROP_USED_SUBDEVS: _tx_subdevs_in_use = val.as(); update_tx_mux_config(); //if the val is bad, this will throw return; - } - throw std::runtime_error("Cannot set on usrp2 dboard"); + case DBOARD_PROP_DBOARD_ID: + _tx_db_eeprom.id = val.as(); + _iface->write_eeprom(I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + return; + + default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + } } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index c639c0dfe..76ee5d6fe 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -136,8 +136,8 @@ public: /*********************************************************************** * EEPROM **********************************************************************/ - void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &buf){ - BOOST_FOREACH(boost::uint8_t byte, buf){ + void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &bytes){ + BOOST_FOREACH(boost::uint8_t byte, bytes){ //write a byte at a time, its easy that way byte_vector_t cmd = boost::assign::list_of(offset)(byte); this->write_i2c(addr, cmd); @@ -145,9 +145,13 @@ public: } byte_vector_t read_eeprom(boost::uint8_t addr, boost::uint8_t offset, size_t num_bytes){ - //do a zero byte write to start read cycle - write_i2c(addr, byte_vector_t(1, offset)); - return read_i2c(addr, num_bytes); + byte_vector_t bytes; + for (size_t i = 0; i < num_bytes; i++){ + //do a zero byte write to start read cycle + write_i2c(addr, byte_vector_t(1, offset)); + bytes.push_back(read_i2c(addr, 1).at(0)); + } + return bytes; } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index dbcee367b..1c9387744 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -161,12 +162,14 @@ private: void rx_dboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _rx_dboard_proxy; uhd::prop_names_t _rx_subdevs_in_use; + uhd::usrp::dboard_eeprom_t _rx_db_eeprom; //properties interface for tx dboard void tx_dboard_get(const wax::obj &, wax::obj &); void tx_dboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _tx_dboard_proxy; uhd::prop_names_t _tx_subdevs_in_use; + uhd::usrp::dboard_eeprom_t _tx_db_eeprom; void update_rx_mux_config(void); void update_tx_mux_config(void); -- cgit v1.2.3 From 61ec6711bb4bbae7a8a26cc631eeb88fb3e7d688 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 25 Apr 2010 22:05:50 -0700 Subject: Work on exceptions. Added props exception macro to make the set/get prop switch statements easier. Made use of boost throw exception macro for throw-site information in throw assert. --- host/CMakeLists.txt | 2 +- host/docs/build.rst | 2 +- host/include/uhd/utils/assert.hpp | 33 ++++++++++++++++---------------- host/include/uhd/utils/props.hpp | 29 ++++++++++++++++++++++++++-- host/include/uhd/utils/safe_main.hpp | 3 +++ host/lib/usrp/dboard/db_basic_and_lf.cpp | 12 ++++++------ host/lib/usrp/dboard/db_rfx.cpp | 14 ++++++-------- host/lib/usrp/dboard/db_xcvr2450.cpp | 15 ++++++++------- host/lib/usrp/usrp2/dboard_impl.cpp | 10 ++++------ host/lib/usrp/usrp2/dsp_impl.cpp | 10 ++++++---- host/lib/usrp/usrp2/mboard_impl.cpp | 8 ++------ host/lib/usrp/usrp2/usrp2_impl.cpp | 3 ++- host/test/gain_handler_test.cpp | 6 +++--- 13 files changed, 86 insertions(+), 61 deletions(-) (limited to 'host/include') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 4ef6278b9..bf8d71b21 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -76,7 +76,7 @@ ENDIF(WIN32) # Setup Boost ######################################################################## SET(Boost_ADDITIONAL_VERSIONS "1.42.0" "1.42") -FIND_PACKAGE(Boost 1.36 REQUIRED COMPONENTS +FIND_PACKAGE(Boost 1.37 REQUIRED COMPONENTS date_time filesystem program_options diff --git a/host/docs/build.rst b/host/docs/build.rst index d28682764..81e61475e 100644 --- a/host/docs/build.rst +++ b/host/docs/build.rst @@ -40,7 +40,7 @@ CMake ^^^^^^^^^^^^^^^^ Boost ^^^^^^^^^^^^^^^^ -* **Version:** at least 3.6 unix, at least 4.0 windows +* **Version:** at least 3.7 unix, at least 4.0 windows * **Required for:** build time + run time * **Download URL:** http://www.boost.org/users/download/ * **Download URL (windows installer):** http://www.boostpro.com/download diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 842ed8dfa..773acd634 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -18,27 +18,27 @@ #ifndef INCLUDED_UHD_UTILS_ASSERT_HPP #define INCLUDED_UHD_UTILS_ASSERT_HPP +#include #include #include #include #include -#include +#include +#include #include +#include namespace uhd{ - class assert_error : public std::logic_error{ - public: - explicit assert_error(const std::string& what_arg) : logic_error(what_arg){ - /* NOP */ - } - }; + //! The exception to throw when assertions fail + struct UHD_API assert_error : virtual std::exception, virtual boost::exception{}; - #define ASSERT_THROW(_x) if (not (_x)) { \ - throw uhd::assert_error(str(boost::format( \ - "Assertion Failed:\n %s:%d\n %s\n ---> %s <---" \ - ) % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION % std::string(#_x))); \ - } + //! The assertion info, the code that failed + typedef boost::error_info assert_info; + + //! Throw an assert error with throw-site information + #define ASSERT_THROW(_x) if (not (_x)) \ + BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x)) /*! * Check that an element is found in a container. @@ -58,17 +58,18 @@ namespace uhd{ ){ if (std::has(iterable, elem)) return; std::string possible_values = ""; - BOOST_FOREACH(T e, iterable){ - if (e != iterable.begin()[0]) possible_values += ", "; + size_t i = 0; + BOOST_FOREACH(const T &e, iterable){ + if (i++ > 0) possible_values += ", "; possible_values += boost::lexical_cast(e); } - throw uhd::assert_error(str(boost::format( + boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format( "Error: %s is not a valid %s. " "Possible values are: [%s]." ) % boost::lexical_cast(elem) % what % possible_values - )); + ))); } }//namespace uhd diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index 6be0b2ce5..bfbca4273 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include #include @@ -35,14 +38,36 @@ namespace uhd{ * \param key a reference to the prop object * \param name a reference to the name object */ - inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file) - extract_named_prop(const wax::obj &key, const std::string &name = ""){ + inline UHD_API named_prop_t extract_named_prop( + const wax::obj &key, + const std::string &name = "" + ){ if (key.type() == typeid(named_prop_t)){ return key.as(); } return named_prop_t(key, name); } + //! The exception to throw for property errors + struct UHD_API prop_error : virtual std::exception, virtual boost::exception{}; + + //! The property error info (verbose or message) + typedef boost::error_info prop_info; + + /*! + * Throw an error when trying to get a write only property. + * Throw-site information will be included with this error. + */ + #define UHD_THROW_PROP_WRITE_ONLY() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get write-only property")) + + /*! + * Throw an error when trying to set a read only property. + * Throw-site information will be included with this error. + */ + #define UHD_THROW_PROP_READ_ONLY() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set read-only property")) + } //namespace uhd #endif /* INCLUDED_UHD_UTILS_PROPS_HPP */ diff --git a/host/include/uhd/utils/safe_main.hpp b/host/include/uhd/utils/safe_main.hpp index b682aa540..a4e4e06e8 100644 --- a/host/include/uhd/utils/safe_main.hpp +++ b/host/include/uhd/utils/safe_main.hpp @@ -19,6 +19,7 @@ #define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP #include +#include #include #include @@ -33,6 +34,8 @@ int main(int argc, char *argv[]){ \ try { \ return _main(argc, argv); \ + } catch(const boost::exception &e){ \ + std::cerr << "Error: " << boost::diagnostic_information(e) << std::endl; \ } catch(const std::exception &e) { \ std::cerr << "Error: " << e.what() << std::endl; \ } catch(...) { \ diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index aad2398d8..c7b841efb 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -153,6 +153,8 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -174,9 +176,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - default: throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_rx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } @@ -248,6 +248,8 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -269,8 +271,6 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - default: throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_tx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 76b2c6d7a..49ec9412c 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -396,6 +396,8 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -419,10 +421,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ set_rx_ant(val.as()); return; - default: - throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_rx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } @@ -486,6 +485,8 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = true; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -509,9 +510,6 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ ASSERT_THROW(val.as() == "TX/RX"); return; - default: - throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_tx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 2c2843d3a..2052511f8 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -352,7 +352,8 @@ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(float &gain){ gain = 5; return max2829_regs_t::TX_BASEBAND_GAIN_5DB; } - ASSERT_THROW(false); + BOOST_THROW_EXCEPTION(std::runtime_error("should not get here")); + return max2829_regs_t::TX_BASEBAND_GAIN_0DB; } /*! @@ -474,6 +475,8 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -496,9 +499,7 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){ this->set_rx_ant(val.as()); return; - default: throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_rx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } @@ -564,6 +565,8 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ case SUBDEV_PROP_USE_LO_OFFSET: val = false; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -586,8 +589,6 @@ void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){ this->set_tx_ant(val.as()); return; - default: throw std::runtime_error(str(boost::format( - "Error: trying to set read-only property on %s subdev" - ) % dboard_id::to_string(get_tx_id()))); + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 8952a9f75..043609458 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -123,8 +123,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _rx_db_eeprom.id; return; - //case DBOARD_PROP_CODEC: - // throw std::runtime_error("unhandled prop in usrp2 dboard"); + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -140,7 +139,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); return; - default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + default: UHD_THROW_PROP_READ_ONLY(); } } @@ -173,8 +172,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _tx_db_eeprom.id; return; - //case DBOARD_PROP_CODEC: - // throw std::runtime_error("unhandled prop in usrp2 dboard"); + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -190,6 +188,6 @@ void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ _iface->write_eeprom(I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); return; - default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 204277ba7..379276f7d 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -117,6 +117,8 @@ void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){ case DSP_PROP_HOST_RATE: val = get_master_clock_freq()/_ddc_decim; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -139,8 +141,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ } return; - default: - throw std::runtime_error("Error: trying to set read-only property on usrp2 ddc0"); + default: UHD_THROW_PROP_READ_ONLY(); } } @@ -200,6 +201,8 @@ void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){ case DSP_PROP_HOST_RATE: val = get_master_clock_freq()/_duc_interp; return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -222,7 +225,6 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ } return; - default: - throw std::runtime_error("Error: trying to set read-only property on usrp2 duc0"); + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index f94806c9f..2c185ec53 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -248,9 +248,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; - default: - throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard"); - + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -306,8 +304,6 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){ issue_ddc_stream_cmd(val.as()); return; - default: - throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard"); - + default: UHD_THROW_PROP_READ_ONLY(); } } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 0fa56c339..11ad812e1 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -202,9 +202,10 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ val = size_t(_max_tx_samples_per_packet); return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } void usrp2_impl::set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("Cannot set in usrp2 device"); + UHD_THROW_PROP_READ_ONLY(); } diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index bf2ec5db7..0669b491a 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -72,6 +72,8 @@ private: case PROP_GAIN_NAMES: val = _gain_values.keys(); return; + + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -87,9 +89,7 @@ private: _gain_values[name] = val.as(); return; - case PROP_GAIN_RANGE: - case PROP_GAIN_NAMES: - throw std::runtime_error("cannot set this property"); + default: UHD_THROW_PROP_READ_ONLY(); } } -- cgit v1.2.3 From 0c609b96574095affe12d9aaa53bead98faba4f3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 00:17:08 -0700 Subject: Added i2c interface to serial.hpp, using in usrp2_iface for i2c and eeprom. --- host/include/uhd/types/serial.hpp | 61 +++++++++++++++++++++++++++++++++++++ host/lib/types.cpp | 27 ++++++++++++++++ host/lib/usrp/usrp2/usrp2_iface.cpp | 21 ------------- host/lib/usrp/usrp2/usrp2_iface.hpp | 48 +---------------------------- 4 files changed, 89 insertions(+), 68 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp index b0fe5d7bd..c134725f5 100644 --- a/host/include/uhd/types/serial.hpp +++ b/host/include/uhd/types/serial.hpp @@ -29,6 +29,67 @@ namespace uhd{ */ typedef std::vector byte_vector_t; + /*! + * The i2c interface class: + * Provides i2c and eeprom functionality. + * A subclass should only have to implement the i2c routines. + * An eeprom implementation comes for free with the interface. + * + * The eeprom routines are implemented on top of i2c. + * The built in eeprom implementation only does single + * byte reads and byte writes over the i2c interface, + * so it should be portable across multiple eeproms. + * Override the eeprom routines if this is not acceptable. + */ + class UHD_API i2c_iface{ + public: + /*! + * Write bytes over the i2c. + * \param addr the address + * \param buf the vector of bytes + */ + virtual void write_i2c( + boost::uint8_t addr, + const byte_vector_t &buf + ) = 0; + + /*! + * Read bytes over the i2c. + * \param addr the address + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual byte_vector_t read_i2c( + boost::uint8_t addr, + size_t num_bytes + ) = 0; + + /*! + * Write bytes to an eeprom. + * \param addr the address + * \param offset byte offset + * \param buf the vector of bytes + */ + virtual void write_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + const byte_vector_t &buf + ); + + /*! + * Read bytes from an eeprom. + * \param addr the address + * \param offset byte offset + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual byte_vector_t read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes + ); + }; + /*! * The SPI configuration struct: * Used to configure a SPI transaction interface. diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 91887840c..a1b9b21a9 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -250,3 +251,29 @@ spi_config_t::spi_config_t(edge_t edge){ mosi_edge = edge; miso_edge = edge; } + +void i2c_iface::write_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + const byte_vector_t &bytes +){ + BOOST_FOREACH(boost::uint8_t byte, bytes){ + //write a byte at a time, its easy that way + byte_vector_t cmd = boost::assign::list_of(offset)(byte); + this->write_i2c(addr, cmd); + } +} + +byte_vector_t i2c_iface::read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes +){ + byte_vector_t bytes; + for (size_t i = 0; i < num_bytes; i++){ + //do a zero byte write to start read cycle + this->write_i2c(addr, byte_vector_t(1, offset)); + bytes.push_back(this->read_i2c(addr, 1).at(0)); + } + return bytes; +} diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 76ee5d6fe..27b6f8907 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -133,27 +133,6 @@ public: return result; } -/*********************************************************************** - * EEPROM - **********************************************************************/ - void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &bytes){ - BOOST_FOREACH(boost::uint8_t byte, bytes){ - //write a byte at a time, its easy that way - byte_vector_t cmd = boost::assign::list_of(offset)(byte); - this->write_i2c(addr, cmd); - } - } - - byte_vector_t read_eeprom(boost::uint8_t addr, boost::uint8_t offset, size_t num_bytes){ - byte_vector_t bytes; - for (size_t i = 0; i < num_bytes; i++){ - //do a zero byte write to start read cycle - write_i2c(addr, byte_vector_t(1, offset)); - bytes.push_back(read_i2c(addr, 1).at(0)); - } - return bytes; - } - /*********************************************************************** * Send/Recv over control **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 938359677..7158c58d0 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -39,7 +39,7 @@ * Provides a set of functions to implementation layer. * Including spi, peek, poke, control... */ -class usrp2_iface : boost::noncopyable{ +class usrp2_iface : public uhd::i2c_iface, boost::noncopyable{ public: typedef boost::shared_ptr sptr; @@ -102,52 +102,6 @@ public: bool readback ) = 0; - /*! - * Write bytes over the i2c. - * \param addr the address - * \param buf the vector of bytes - */ - virtual void write_i2c( - boost::uint8_t addr, - const uhd::byte_vector_t &buf - ) = 0; - - /*! - * Read bytes over the i2c. - * \param addr the address - * \param num_bytes number of bytes to read - * \return a vector of bytes - */ - virtual uhd::byte_vector_t read_i2c( - boost::uint8_t addr, - size_t num_bytes - ) = 0; - - /*! - * Write bytes to an eeprom. - * \param addr the address - * \param offset byte offset - * \param buf the vector of bytes - */ - virtual void write_eeprom( - boost::uint8_t addr, - boost::uint8_t offset, - const uhd::byte_vector_t &buf - ) = 0; - - /*! - * Read bytes from an eeprom. - * \param addr the address - * \param offset byte offset - * \param num_bytes number of bytes to read - * \return a vector of bytes - */ - virtual uhd::byte_vector_t read_eeprom( - boost::uint8_t addr, - boost::uint8_t offset, - size_t num_bytes - ) = 0; - /*! * Get the master clock frequency. * \return the frequency in Hz -- cgit v1.2.3 From 1217b8d67c3bef98195836fe10ab39576642b340 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 12:16:37 -0700 Subject: Got eeprom read/write dboard ids working. Moved named prop implementation into cpp, and made named prop a struct (tuples are trouble). --- host/include/uhd/utils/props.hpp | 29 ++++++++++++++++-------- host/lib/CMakeLists.txt | 1 + host/lib/types.cpp | 8 ++++--- host/lib/usrp/dboard_eeprom.cpp | 21 ++++++++++++++---- host/lib/usrp/dboard_manager.cpp | 5 +++-- host/lib/usrp/usrp2/dboard_impl.cpp | 2 +- host/lib/utils.cpp | 44 +++++++++++++++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 host/lib/utils.cpp (limited to 'host/include') diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index bfbca4273..768655e36 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -29,24 +29,35 @@ namespace uhd{ - //typedef for handling named properties + //! The type for a vector of property names typedef std::vector prop_names_t; - typedef boost::tuple named_prop_t; + + /*! + * A named prop struct holds a key and a name. + * Allows properties to be sub-sectioned by name. + */ + struct UHD_API named_prop_t{ + wax::obj key; + std::string name; + + /*! + * Create a new named prop from key and name. + * \param key the property key + * \param name the string name + */ + named_prop_t(const wax::obj &key, const std::string &name); + }; /*! * Utility function to separate a named property into its components. * \param key a reference to the prop object * \param name a reference to the name object + * \return a tuple that can be used with boost::tie */ - inline UHD_API named_prop_t extract_named_prop( + UHD_API boost::tuple extract_named_prop( const wax::obj &key, const std::string &name = "" - ){ - if (key.type() == typeid(named_prop_t)){ - return key.as(); - } - return named_prop_t(key, name); - } + ); //! The exception to throw for property errors struct UHD_API prop_error : virtual std::exception, virtual boost::exception{}; diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index ffbf15484..5252eda8f 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -50,6 +50,7 @@ SET(libuhd_sources gain_handler.cpp load_modules.cpp types.cpp + utils.cpp wax.cpp transport/convert_types.cpp transport/if_addrs.cpp diff --git a/host/lib/types.cpp b/host/lib/types.cpp index a1b9b21a9..08e41b62f 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -257,10 +258,11 @@ void i2c_iface::write_eeprom( boost::uint8_t offset, const byte_vector_t &bytes ){ - BOOST_FOREACH(boost::uint8_t byte, bytes){ + for (size_t i = 0; i < bytes.size(); i++){ //write a byte at a time, its easy that way - byte_vector_t cmd = boost::assign::list_of(offset)(byte); + byte_vector_t cmd = boost::assign::list_of(offset+i)(bytes[i]); this->write_i2c(addr, cmd); + boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write } } @@ -272,7 +274,7 @@ byte_vector_t i2c_iface::read_eeprom( byte_vector_t bytes; for (size_t i = 0; i < num_bytes; i++){ //do a zero byte write to start read cycle - this->write_i2c(addr, byte_vector_t(1, offset)); + this->write_i2c(addr, byte_vector_t(1, offset+i)); bytes.push_back(this->read_i2c(addr, 1).at(0)); } return bytes; diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index 5ce0b2328..00236c337 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -17,10 +17,14 @@ #include #include +#include +#include using namespace uhd; using namespace uhd::usrp; +static const bool _dboard_eeprom_debug = false; + //////////////////////////////////////////////////////////////////////// // format of daughterboard EEPROM // 00: 0xDB code for ``I'm a daughterboard'' @@ -55,14 +59,23 @@ using namespace uhd::usrp; //negative sum of bytes excluding checksum byte static boost::uint8_t checksum(const byte_vector_t &bytes){ - int sum; - for (size_t i = 0; i < DB_EEPROM_CHKSUM; i++){ - sum += int(bytes.at(i)); + int sum = 0; + for (size_t i = 0; i < std::min(bytes.size(), size_t(DB_EEPROM_CHKSUM)); i++){ + sum -= int(bytes.at(i)); } - return (-sum) & 0xff; + if (_dboard_eeprom_debug) + std::cout << boost::format("sum: 0x%02x") % sum << std::endl; + return boost::uint8_t(sum); } dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ + if (_dboard_eeprom_debug){ + for (size_t i = 0; i < bytes.size(); i++){ + std::cout << boost::format( + "eeprom byte[0x%02x] = 0x%02x") % i % int(bytes.at(i) + ) << std::endl; + } + } try{ ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 06f8c55b6..34b635934 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -177,10 +177,11 @@ static args_t get_dboard_args( //verify that there is a registered constructor for this id if (not get_id_to_args_map().has_key(dboard_id)){ - throw std::runtime_error(str( + /*throw std::runtime_error(str( boost::format("Unregistered %s dboard id: %s") % xx_type % dboard_id::to_string(dboard_id) - )); + ));*/ + return get_dboard_args(dboard_id::NONE, xx_type); } //return the dboard args for this id diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 043609458..a68ae240e 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -136,7 +136,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ case DBOARD_PROP_DBOARD_ID: _rx_db_eeprom.id = val.as(); - _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes()); return; default: UHD_THROW_PROP_READ_ONLY(); diff --git a/host/lib/utils.cpp b/host/lib/utils.cpp new file mode 100644 index 000000000..3a1e5aa3f --- /dev/null +++ b/host/lib/utils.cpp @@ -0,0 +1,44 @@ +// +// 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; + +/*********************************************************************** + * Props + **********************************************************************/ +named_prop_t::named_prop_t( + const wax::obj &key_, + const std::string &name_ +){ + key = key_; + name = name_; +} + +typedef boost::tuple named_prop_tuple; + +named_prop_tuple uhd::extract_named_prop( + const wax::obj &key, + const std::string &name +){ + if (key.type() == typeid(named_prop_t)){ + named_prop_t np = key.as(); + return named_prop_tuple(np.key, np.name); + } + return named_prop_tuple(key, name); +} -- cgit v1.2.3 From 90ed2e3a80eef0be3a7270364335f0e82f004cc1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 14:42:32 -0700 Subject: prefixed the ASSERT_THROW macro with UHD for the sake of namespace --- host/include/uhd/utils/assert.hpp | 2 +- host/lib/device.cpp | 4 ++-- host/lib/transport/convert_types.cpp | 4 ++-- host/lib/usrp/dboard/db_basic_and_lf.cpp | 8 ++++---- host/lib/usrp/dboard/db_rfx.cpp | 10 +++++----- host/lib/usrp/dboard/db_xcvr2450.cpp | 4 ++-- host/lib/usrp/dboard_eeprom.cpp | 6 +++--- host/lib/usrp/dboard_manager.cpp | 2 +- host/lib/usrp/usrp2/dboard_impl.cpp | 4 ++-- host/lib/usrp/usrp2/dsp_impl.cpp | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 18 +++++++++--------- host/lib/usrp/usrp2/usrp2_iface.cpp | 16 ++++++++-------- host/lib/usrp/usrp2/usrp2_impl.cpp | 2 +- 13 files changed, 41 insertions(+), 41 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 773acd634..01beed757 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -37,7 +37,7 @@ namespace uhd{ typedef boost::error_info assert_info; //! Throw an assert error with throw-site information - #define ASSERT_THROW(_x) if (not (_x)) \ + #define UHD_ASSERT_THROW(_x) if (not (_x)) \ BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x)) /*! diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 0197a6232..706f64951 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -132,8 +132,8 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ //try to find an existing device try{ - ASSERT_THROW(hash_to_device.has_key(dev_hash)); - ASSERT_THROW(not hash_to_device[dev_hash].expired()); + UHD_ASSERT_THROW(hash_to_device.has_key(dev_hash)); + UHD_ASSERT_THROW(not hash_to_device[dev_hash].expired()); return hash_to_device[dev_hash].lock(); } //create and register a new device diff --git a/host/lib/transport/convert_types.cpp b/host/lib/transport/convert_types.cpp index d7602c049..8c3d6b17a 100644 --- a/host/lib/transport/convert_types.cpp +++ b/host/lib/transport/convert_types.cpp @@ -110,7 +110,7 @@ void transport::convert_io_type_to_otw_type( size_t num_samps ){ //all we handle for now: - ASSERT_THROW(otw_type.width == 16 and otw_type.byteorder == otw_type_t::BO_BIG_ENDIAN); + UHD_ASSERT_THROW(otw_type.width == 16 and otw_type.byteorder == otw_type_t::BO_BIG_ENDIAN); switch(io_type.tid){ case io_type_t::COMPLEX_FLOAT32: @@ -130,7 +130,7 @@ void transport::convert_otw_type_to_io_type( size_t num_samps ){ //all we handle for now: - ASSERT_THROW(otw_type.width == 16 and otw_type.byteorder == otw_type_t::BO_BIG_ENDIAN); + UHD_ASSERT_THROW(otw_type.width == 16 and otw_type.byteorder == otw_type_t::BO_BIG_ENDIAN); switch(io_type.tid){ case io_type_t::COMPLEX_FLOAT32: diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index c7b841efb..4ca2ef9b1 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -166,11 +166,11 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()){ case SUBDEV_PROP_GAIN: - ASSERT_THROW(val.as() == float(0)); + UHD_ASSERT_THROW(val.as() == float(0)); return; case SUBDEV_PROP_ANTENNA: - ASSERT_THROW(val.as() == std::string("")); + UHD_ASSERT_THROW(val.as() == std::string("")); return; case SUBDEV_PROP_FREQ: @@ -261,11 +261,11 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()){ case SUBDEV_PROP_GAIN: - ASSERT_THROW(val.as() == float(0)); + UHD_ASSERT_THROW(val.as() == float(0)); return; case SUBDEV_PROP_ANTENNA: - ASSERT_THROW(val.as() == std::string("")); + UHD_ASSERT_THROW(val.as() == std::string("")); return; case SUBDEV_PROP_FREQ: diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 49ec9412c..14879dbed 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -192,7 +192,7 @@ void rfx_xcvr::set_tx_lo_freq(double freq){ void rfx_xcvr::set_rx_ant(const std::string &ant){ //validate input - ASSERT_THROW(ant == "TX/RX" or ant == "RX2"); + UHD_ASSERT_THROW(ant == "TX/RX" or ant == "RX2"); //set the rx atr regs that change with antenna setting this->get_iface()->set_atr_reg( @@ -350,12 +350,12 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - ASSERT_THROW(name == "PGA0"); + UHD_ASSERT_THROW(name == "PGA0"); val = _rx_pga0_gain; return; case SUBDEV_PROP_GAIN_RANGE: - ASSERT_THROW(name == "PGA0"); + UHD_ASSERT_THROW(name == "PGA0"); val = gain_range_t(0, _max_rx_pga0_gain, float(0.022)); return; @@ -413,7 +413,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ return; case SUBDEV_PROP_GAIN: - ASSERT_THROW(name == "PGA0"); + UHD_ASSERT_THROW(name == "PGA0"); set_rx_pga0_gain(val.as()); return; @@ -507,7 +507,7 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_ANTENNA: //its always set to tx/rx, so we only allow this value - ASSERT_THROW(val.as() == "TX/RX"); + UHD_ASSERT_THROW(val.as() == "TX/RX"); return; default: UHD_THROW_PROP_READ_ONLY(); diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 2052511f8..576d08848 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -395,7 +395,7 @@ void xcvr2450::set_tx_gain(float gain, const std::string &name){ _max2829_regs.tx_baseband_gain = gain_to_tx_bb_reg(gain); send_reg(0x9); } - else ASSERT_THROW(false); + else UHD_ASSERT_THROW(false); _tx_gains[name] = gain; } @@ -409,7 +409,7 @@ void xcvr2450::set_rx_gain(float gain, const std::string &name){ _max2829_regs.rx_lna_gain = gain_to_rx_lna_reg(gain); send_reg(0xB); } - else ASSERT_THROW(false); + else UHD_ASSERT_THROW(false); _rx_gains[name] = gain; } diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index 00236c337..1404ed1e6 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -77,9 +77,9 @@ dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ } } try{ - ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); - ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); - ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); + UHD_ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); + UHD_ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + UHD_ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); id = \ (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) | (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ; diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 34b635934..390c1d3c9 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -206,7 +206,7 @@ dboard_manager_impl::dboard_manager_impl( //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); + UHD_ASSERT_THROW(rx_subdevs == tx_subdevs); BOOST_FOREACH(const std::string &subdev, rx_subdevs){ dboard_base::sptr xcvr_dboard = rx_dboard_ctor( dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, tx_dboard_id) diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index a68ae240e..226a7950d 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -66,7 +66,7 @@ void usrp2_impl::dboard_init(void){ void usrp2_impl::update_rx_mux_config(void){ //calculate the rx mux boost::uint32_t rx_mux = 0; - ASSERT_THROW(_rx_subdevs_in_use.size() == 1); + UHD_ASSERT_THROW(_rx_subdevs_in_use.size() == 1); wax::obj rx_subdev = _dboard_manager->get_rx_subdev(_rx_subdevs_in_use.at(0)); std::cout << "Using: " << rx_subdev[SUBDEV_PROP_NAME].as() << std::endl; if (rx_subdev[SUBDEV_PROP_QUADRATURE].as()){ @@ -84,7 +84,7 @@ void usrp2_impl::update_rx_mux_config(void){ void usrp2_impl::update_tx_mux_config(void){ //calculate the tx mux boost::uint32_t tx_mux = 0x10; - ASSERT_THROW(_tx_subdevs_in_use.size() == 1); + UHD_ASSERT_THROW(_tx_subdevs_in_use.size() == 1); wax::obj tx_subdev = _dboard_manager->get_tx_subdev(_tx_subdevs_in_use.at(0)); std::cout << "Using: " << tx_subdev[SUBDEV_PROP_NAME].as() << std::endl; if (tx_subdev[SUBDEV_PROP_IQ_SWAPPED].as()){ diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 379276f7d..84c50ac0d 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -40,7 +40,7 @@ template T log2(T num){ * DDC Helper Methods **********************************************************************/ static boost::uint32_t calculate_freq_word_and_update_actual_freq(double &freq, double clock_freq){ - ASSERT_THROW(std::abs(freq) < clock_freq/2.0); + UHD_ASSERT_THROW(std::abs(freq) < clock_freq/2.0); static const double scale_factor = std::pow(2.0, 32); //calculate the freq register word diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 2c185ec53..684cf245d 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -152,7 +152,7 @@ void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){ //send and recv usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE); } /*********************************************************************** @@ -171,7 +171,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ //send and recv usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE); //extract the address val = mac_addr_t::from_bytes(in_data.data.mac_addr).to_string(); @@ -185,7 +185,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ //send and recv usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE); //extract the address val = boost::asio::ip::address_v4(ntohl(in_data.data.ip_addr)).to_string(); @@ -209,7 +209,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _rx_dboard_proxy->get_link(); return; @@ -218,7 +218,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _tx_dboard_proxy->get_link(); return; @@ -227,7 +227,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DSP: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _rx_dsp_proxy->get_link(); return; @@ -236,7 +236,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DSP: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _tx_dsp_proxy->get_link(); return; @@ -267,7 +267,7 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){ //send and recv usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE); return; } @@ -279,7 +279,7 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){ //send and recv usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE); return; } } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 27b6f8907..5bca2c95b 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -86,7 +86,7 @@ public: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE); return ntohl(out_data.data.spi_args.data); } @@ -102,14 +102,14 @@ public: out_data.data.i2c_args.bytes = buf.size(); //limitation of i2c transaction size - ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data)); + UHD_ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data)); //copy in the data std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data); //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE); } byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){ @@ -120,12 +120,12 @@ public: out_data.data.i2c_args.bytes = num_bytes; //limitation of i2c transaction size - ASSERT_THROW(num_bytes <= sizeof(out_data.data.i2c_args.data)); + UHD_ASSERT_THROW(num_bytes <= sizeof(out_data.data.i2c_args.data)); //send and recv usrp2_ctrl_data_t in_data = this->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); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE); + UHD_ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes); //copy out the data byte_vector_t result(num_bytes); @@ -193,7 +193,7 @@ private: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE); } template T peek(boost::uint32_t addr){ @@ -205,7 +205,7 @@ private: //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); + UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); return T(ntohl(out_data.data.poke_args.data)); } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 11ad812e1..d9b2248ff 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -186,7 +186,7 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ return; case DEVICE_PROP_MBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _mboard_proxy->get_link(); return; -- cgit v1.2.3 From b1992806e130216fdab963c2154f489189b8c3b5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 15:13:29 -0700 Subject: added lock detect status to dboards --- host/include/uhd/usrp/subdev_props.hpp | 8 ++++---- host/lib/usrp/dboard/db_basic_and_lf.cpp | 8 ++++++++ host/lib/usrp/dboard/db_rfx.cpp | 17 +++++++++++++++++ host/lib/usrp/dboard/db_xcvr2450.cpp | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp index cd6b14ef5..1f8e91d68 100644 --- a/host/include/uhd/usrp/subdev_props.hpp +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -35,13 +35,13 @@ namespace uhd{ namespace usrp{ SUBDEV_PROP_FREQ_RANGE = 'F', //ro, freq_range_t SUBDEV_PROP_ANTENNA = 'a', //rw, std::string SUBDEV_PROP_ANTENNA_NAMES = 'A', //ro, prop_names_t - //SUBDEV_PROP_ENABLED = 'e', //rw, bool //---> dont need, we have atr + SUBDEV_PROP_LO_LOCKED = 'L', //ro, bool SUBDEV_PROP_QUADRATURE = 'q', //ro, bool SUBDEV_PROP_IQ_SWAPPED = 'i', //ro, bool SUBDEV_PROP_SPECTRUM_INVERTED = 's', //ro, bool - SUBDEV_PROP_USE_LO_OFFSET = 'l' //ro, bool - //SUBDEV_PROP_RSSI, //ro, float //----> not on all boards, use named prop - //SUBDEV_PROP_BANDWIDTH //rw, double //----> not on all boards, use named prop + SUBDEV_PROP_USE_LO_OFFSET = 'l', //ro, bool + SUBDEV_PROP_RSSI = 'R', //ro, float + SUBDEV_PROP_BANDWIDTH = 'B' //rw, double }; }} //namespace diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index 4ca2ef9b1..fa53bd964 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -154,6 +154,10 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; + case SUBDEV_PROP_LO_LOCKED: + val = true; //there is no LO, so it must be true! + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -249,6 +253,10 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; + case SUBDEV_PROP_LO_LOCKED: + val = true; //there is no LO, so it must be true! + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 14879dbed..6ad5ad906 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -94,6 +94,15 @@ private: * \return the actual frequency in Hz */ double set_lo_freq(dboard_iface::unit_t unit, double target_freq); + + /*! + * Get the lock detect status of the LO. + * \param unit which unit rx or tx + * \return true for locked + */ + bool get_locked(dboard_iface::unit_t unit){ + return (this->get_iface()->read_gpio(unit) & LOCKDET_MASK) != 0; + } }; /*********************************************************************** @@ -397,6 +406,10 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; + case SUBDEV_PROP_LO_LOCKED: + val = this->get_locked(dboard_iface::UNIT_RX); + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -486,6 +499,10 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ val = true; return; + case SUBDEV_PROP_LO_LOCKED: + val = this->get_locked(dboard_iface::UNIT_TX); + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 576d08848..5b932904d 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -126,6 +126,14 @@ private: } static bool is_highband(double freq){return freq > 3e9;} + + /*! + * Is the LO locked? + * \return true for locked + */ + bool get_locked(void){ + return (this->get_iface()->read_gpio(dboard_iface::UNIT_RX) & LOCKDET_RXIO) != 0; + } }; /*********************************************************************** @@ -476,6 +484,10 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; + case SUBDEV_PROP_LO_LOCKED: + val = this->get_locked(); + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } @@ -566,6 +578,10 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; + case SUBDEV_PROP_LO_LOCKED: + val = this->get_locked(); + return; + default: UHD_THROW_PROP_WRITE_ONLY(); } } -- cgit v1.2.3 From 6f1bdcb58608e3a7c2625841e3a8f1c6297bb544 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 15:20:18 -0700 Subject: Renamed the prop set/get error macros so they make sense for not-implemented properties. --- host/include/uhd/utils/props.hpp | 12 ++++++------ host/lib/usrp/dboard/db_basic_and_lf.cpp | 8 ++++---- host/lib/usrp/dboard/db_rfx.cpp | 8 ++++---- host/lib/usrp/dboard/db_xcvr2450.cpp | 8 ++++---- host/lib/usrp/usrp2/dboard_impl.cpp | 8 ++++---- host/lib/usrp/usrp2/dsp_impl.cpp | 8 ++++---- host/lib/usrp/usrp2/mboard_impl.cpp | 4 ++-- host/lib/usrp/usrp2/usrp2_impl.cpp | 4 ++-- host/test/gain_handler_test.cpp | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index 768655e36..516102a5f 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -66,18 +66,18 @@ namespace uhd{ typedef boost::error_info prop_info; /*! - * Throw an error when trying to get a write only property. + * Throw when getting a not-implemented or write-only property. * Throw-site information will be included with this error. */ - #define UHD_THROW_PROP_WRITE_ONLY() \ - BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get write-only property")) + #define UHD_THROW_PROP_GET_ERROR() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get this property")) /*! - * Throw an error when trying to set a read only property. + * Throw when setting a not-implemented or read-only property. * Throw-site information will be included with this error. */ - #define UHD_THROW_PROP_READ_ONLY() \ - BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set read-only property")) + #define UHD_THROW_PROP_SET_ERROR() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set this property")) } //namespace uhd diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index fa53bd964..b0fbbd2ec 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -158,7 +158,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ val = true; //there is no LO, so it must be true! return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -180,7 +180,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } @@ -257,7 +257,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ val = true; //there is no LO, so it must be true! return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -279,6 +279,6 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ case SUBDEV_PROP_FREQ: return; // it wont do you much good, but you can set it - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 6ad5ad906..175f55eab 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -410,7 +410,7 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ val = this->get_locked(dboard_iface::UNIT_RX); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -434,7 +434,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){ set_rx_ant(val.as()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } @@ -503,7 +503,7 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ val = this->get_locked(dboard_iface::UNIT_TX); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -527,6 +527,6 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){ UHD_ASSERT_THROW(val.as() == "TX/RX"); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 5b932904d..f1510da10 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -488,7 +488,7 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ val = this->get_locked(); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -511,7 +511,7 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){ this->set_rx_ant(val.as()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } @@ -582,7 +582,7 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ val = this->get_locked(); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -605,6 +605,6 @@ void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){ this->set_tx_ant(val.as()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 226a7950d..403faf5cf 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -123,7 +123,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _rx_db_eeprom.id; return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -139,7 +139,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } @@ -172,7 +172,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _tx_db_eeprom.id; return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -188,6 +188,6 @@ void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ _iface->write_eeprom(I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 84c50ac0d..84314a656 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -118,7 +118,7 @@ void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){ val = get_master_clock_freq()/_ddc_decim; return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -141,7 +141,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ } return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } @@ -202,7 +202,7 @@ void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){ val = get_master_clock_freq()/_duc_interp; return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -225,6 +225,6 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ } return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 684cf245d..36bef4f25 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -248,7 +248,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -304,6 +304,6 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){ issue_ddc_stream_cmd(val.as()); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index d9b2248ff..4079357f9 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -202,10 +202,10 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ val = size_t(_max_tx_samples_per_packet); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } void usrp2_impl::set(const wax::obj &, const wax::obj &){ - UHD_THROW_PROP_READ_ONLY(); + UHD_THROW_PROP_SET_ERROR(); } diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index 0669b491a..5a9f2b714 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -73,7 +73,7 @@ private: val = _gain_values.keys(); return; - default: UHD_THROW_PROP_WRITE_ONLY(); + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -89,7 +89,7 @@ private: _gain_values[name] = val.as(); return; - default: UHD_THROW_PROP_READ_ONLY(); + default: UHD_THROW_PROP_SET_ERROR(); } } -- cgit v1.2.3 From a62ff5290ab931a8c57f743e54e030c07964e568 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 18:13:09 -0700 Subject: added simple usrp api to read rssi and get LO lock status --- host/include/uhd/usrp/simple_usrp.hpp | 11 +++++++++++ host/lib/usrp/simple_usrp.cpp | 12 ++++++++++++ 2 files changed, 23 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index e3f181ec3..c4142b4e6 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -98,6 +98,13 @@ public: */ virtual void set_clock_config(const clock_config_t &clock_config) = 0; + /*! + * Read the RSSI value from a usrp device. + * Or throw if the dboard does not support an RSSI readback. + * \return the rssi in dB + */ + virtual float read_rssi(void) = 0; + /******************************************************************* * RX methods ******************************************************************/ @@ -115,6 +122,8 @@ public: virtual std::string get_rx_antenna(void) = 0; virtual std::vector get_rx_antennas(void) = 0; + virtual bool get_rx_lo_locked(void) = 0; + /******************************************************************* * TX methods ******************************************************************/ @@ -131,6 +140,8 @@ public: virtual void set_tx_antenna(const std::string &ant) = 0; virtual std::string get_tx_antenna(void) = 0; virtual std::vector get_tx_antennas(void) = 0; + + virtual bool get_tx_lo_locked(void) = 0; }; }} diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index 321d66a4a..a8c104485 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -102,6 +102,10 @@ public: _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; } + float read_rssi(void){ + return _rx_subdev[SUBDEV_PROP_RSSI].as(); + } + /******************************************************************* * RX methods ******************************************************************/ @@ -145,6 +149,10 @@ public: return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as(); } + bool get_rx_lo_locked(void){ + return _rx_subdev[SUBDEV_PROP_LO_LOCKED].as(); + } + /******************************************************************* * TX methods ******************************************************************/ @@ -188,6 +196,10 @@ public: return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as(); } + bool get_tx_lo_locked(void){ + return _tx_subdev[SUBDEV_PROP_LO_LOCKED].as(); + } + private: device::sptr _dev; wax::obj _mboard; -- cgit v1.2.3 From 8bf1ad45de2c81e5bea9f2ba4330ee1f8ce18bc7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Apr 2010 23:41:39 -0700 Subject: added to the time spec documentation --- host/include/uhd/types/time_spec.hpp | 23 +++++++++++++++++------ host/lib/types.cpp | 6 +++--- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/time_spec.hpp b/host/include/uhd/types/time_spec.hpp index f06d27118..25d9e41d0 100644 --- a/host/include/uhd/types/time_spec.hpp +++ b/host/include/uhd/types/time_spec.hpp @@ -28,10 +28,19 @@ namespace uhd{ * The time_spec_t can be used when setting the time on devices, * and for dealing with time stamped samples though the metadata. * and for controlling the start of streaming for applicable dsps. + * + * The fractional seconds are represented in units of nanoseconds, + * which provide a clock-domain independent unit of time storage. + * The methods "get_ticks" and "set_ticks" can be used to convert + * the fractional seconds to and from clock-domain specific units. + * + * The nanoseconds count is stored as double precision floating point. + * This gives the fractional seconds enough precision to unambiguously + * specify a clock-tick/sample-count up to rates of several petahertz. */ struct UHD_API time_spec_t{ - //! whole seconds count + //! whole/integer seconds count in seconds boost::uint32_t secs; //! fractional seconds count in nano-seconds @@ -39,24 +48,26 @@ namespace uhd{ /*! * Convert the fractional nsecs to clock ticks. + * Translation into clock-domain specific units. * \param tick_rate the number of ticks per second - * \return the number of ticks in this time spec + * \return the fractional seconds tick count */ boost::uint32_t get_ticks(double tick_rate) const; /*! * Set the fractional nsecs from clock ticks. + * Translation from clock-domain specific units. * \param ticks the fractional seconds tick count * \param tick_rate the number of ticks per second */ void set_ticks(boost::uint32_t ticks, double tick_rate); /*! - * Create a time_spec_t from seconds and ticks. - * \param new_secs the new seconds (default = 0) - * \param new_nsecs the new nano-seconds (default = 0) + * Create a time_spec_t from whole and fractional seconds. + * \param secs the whole/integer seconds count in seconds (default = 0) + * \param nsecs the fractional seconds count in nanoseconds (default = 0) */ - time_spec_t(boost::uint32_t new_secs = 0, double new_nsecs = 0); + time_spec_t(boost::uint32_t secs = 0, double nsecs = 0); }; diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 08e41b62f..14f7651d4 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -105,9 +105,9 @@ tx_metadata_t::tx_metadata_t(void){ /*********************************************************************** * time spec **********************************************************************/ -time_spec_t::time_spec_t(boost::uint32_t new_secs, double new_nsecs){ - secs = new_secs; - nsecs = new_nsecs; +time_spec_t::time_spec_t(boost::uint32_t secs_, double nsecs_){ + secs = secs_; + nsecs = nsecs_; } boost::uint32_t time_spec_t::get_ticks(double tick_rate) const{ -- cgit v1.2.3