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/lib/types.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'host/lib/types.cpp') 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; +} -- 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/lib/types.cpp') 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 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/lib/types.cpp') 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/lib/types.cpp') 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 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/lib/types.cpp') 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