aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-08-31 16:45:49 -0700
committerNick Foster <nick@nerdnetworks.org>2010-08-31 16:45:49 -0700
commit0616872e35ac6429c19c2495bf4e378551bdd60e (patch)
tree6116f992f4f6d1f8d701aca6bf1526a85d8bda89 /host
parentb96088b692a5c44974919ee36e253b6ea8c51972 (diff)
parent9a3217cbbeb39d677a439fe0982a7ac4d7f251c2 (diff)
downloaduhd-0616872e35ac6429c19c2495bf4e378551bdd60e.tar.gz
uhd-0616872e35ac6429c19c2495bf4e378551bdd60e.tar.bz2
uhd-0616872e35ac6429c19c2495bf4e378551bdd60e.zip
Merge branch 'usrp1' of ettus.sourcerepo.com:ettus/uhdpriv into usrp1
Diffstat (limited to 'host')
-rw-r--r--host/docs/build.rst8
-rw-r--r--host/docs/usrp1.rst35
-rw-r--r--host/docs/usrp2.rst15
-rw-r--r--host/examples/CMakeLists.txt4
-rw-r--r--host/examples/pps_test.cpp86
-rw-r--r--host/examples/tx_waveforms.cpp19
-rw-r--r--host/include/uhd/transport/CMakeLists.txt1
-rw-r--r--host/include/uhd/transport/convert_types.hpp37
-rw-r--r--host/include/uhd/transport/convert_types.ipp43
-rw-r--r--host/include/uhd/usrp/subdev_spec.hpp9
-rw-r--r--host/lib/transport/convert_types_impl.hpp27
-rwxr-xr-xhost/lib/transport/gen_convert_types.py107
-rw-r--r--host/lib/usrp/dboard/db_dbsrx.cpp7
-rw-r--r--host/lib/usrp/misc_utils.cpp13
-rw-r--r--host/lib/usrp/usrp1/dboard_iface.cpp6
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp4
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp22
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp4
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp10
-rw-r--r--host/test/convert_types_test.cpp84
20 files changed, 482 insertions, 59 deletions
diff --git a/host/docs/build.rst b/host/docs/build.rst
index 8f0d0db59..d7dfd05e5 100644
--- a/host/docs/build.rst
+++ b/host/docs/build.rst
@@ -53,6 +53,14 @@ Boost
* **Download URL (windows installer):** http://www.boostpro.com/download
^^^^^^^^^^^^^^^^
+LibUSB
+^^^^^^^^^^^^^^^^
+* **Purpose:** USB userspace library
+* **Version:** at least 1.0
+* **Required for:** build time + run time (optional)
+* **Download URL:** http://www.libusb.org/
+
+^^^^^^^^^^^^^^^^
Python
^^^^^^^^^^^^^^^^
* **Purpose:** used by Cheetah and utility scripts
diff --git a/host/docs/usrp1.rst b/host/docs/usrp1.rst
index ebc33cbfa..c960b928b 100644
--- a/host/docs/usrp1.rst
+++ b/host/docs/usrp1.rst
@@ -22,6 +22,41 @@ Change the USRP1's serial number
TODO
------------------------------------------------------------------------
+Specifying the subdevice to use
+------------------------------------------------------------------------
+The USRP1 has multiple daughterboard slots, known as slot A and slot B.
+The subdevice specification can be used to select
+the daughterboard and subdevice for each channel.
+For daughterboards with one one subdevice,
+the subdevice name may be left blank for automatic selection.
+
+Ex: The subdev spec markup string to select a WBX on slot B.
+Notice the use of the blank subdevice name for automatic selection.
+
+::
+
+ B:
+
+ -- OR --
+
+ B:0
+
+Ex: The subdev spec markup string to select a BasicRX on slot B.
+Notice that the subdevice name is always specified in the 3 possible cases.
+
+::
+
+ B:AB
+
+ -- OR --
+
+ B:A
+
+ -- OR --
+
+ B:B
+
+------------------------------------------------------------------------
OS Specific Notes
------------------------------------------------------------------------
diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst
index 3ac326f58..0d48209be 100644
--- a/host/docs/usrp2.rst
+++ b/host/docs/usrp2.rst
@@ -205,3 +205,18 @@ Example, set the args string to the following:
::
addr=192.168.10.2, recv_buff_size=100e6
+
+------------------------------------------------------------------------
+Hardware setup notes
+------------------------------------------------------------------------
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Ref Clock - 10MHz
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Using an external 10MHz reference clock requires a signal level between +5dBm and +20dBm at 10MHz applied to the Ref Clock SMA port on the front panel.
+
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+PPS - Pulse Per Second
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Using a PPS signal for timestamp synchronization requires a 5Vpp square wave signal
diff --git a/host/examples/CMakeLists.txt b/host/examples/CMakeLists.txt
index c3bbbcd04..5b241e284 100644
--- a/host/examples/CMakeLists.txt
+++ b/host/examples/CMakeLists.txt
@@ -28,10 +28,14 @@ TARGET_LINK_LIBRARIES(tx_timed_samples uhd)
ADD_EXECUTABLE(tx_waveforms tx_waveforms.cpp)
TARGET_LINK_LIBRARIES(tx_waveforms uhd)
+ADD_EXECUTABLE(pps_test pps_test.cpp)
+TARGET_LINK_LIBRARIES(pps_test uhd)
+
INSTALL(TARGETS
benchmark_rx_rate
rx_timed_samples
tx_timed_samples
tx_waveforms
+ pps_test
RUNTIME DESTINATION ${PKG_DATA_DIR}/examples
)
diff --git a/host/examples/pps_test.cpp b/host/examples/pps_test.cpp
new file mode 100644
index 000000000..c25cbe94f
--- /dev/null
+++ b/host/examples/pps_test.cpp
@@ -0,0 +1,86 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <uhd/usrp/simple_usrp.hpp>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <boost/thread.hpp>
+#include <iostream>
+#include <complex>
+
+namespace po = boost::program_options;
+
+int UHD_SAFE_MAIN(int argc, char *argv[]){
+ uhd::set_thread_priority_safe();
+
+ //variables to be set by po
+ std::string args;
+ float seconds;
+
+ //setup the program options
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "help message")
+ ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
+ ;
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ //print the help message
+ if (vm.count("help")){
+ std::cout << boost::format("UHD PPS Test %s") % desc << std::endl;
+ return ~0;
+ }
+
+ //create a usrp device
+ std::cout << std::endl;
+ 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_pp_string() << std::endl;
+
+ //set a known time value
+ std::cout << "Set time to known value (100.0) without regard to pps:" << std::endl;
+ sdev->set_time_now(uhd::time_spec_t(100.0));
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ std::cout << boost::format("Reading time 1 second later: %f\n") % (sdev->get_time_now().get_full_secs()) << std::endl;
+
+ //store the time to see if PPS resets it
+ seconds = sdev->get_time_now().get_full_secs();
+
+ //set a known time at next PPS, check that time increments
+ uhd::time_spec_t time_spec = uhd::time_spec_t(0.0);
+ std::cout << "Set time to known value (0.0) at next pps:" << std::endl;
+ sdev->set_time_next_pps(time_spec);
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ std::cout << boost::format("Reading time 1 second later: %f\n") % (sdev->get_time_now().get_full_secs()) << std::endl;
+
+ //finished
+ if (seconds > sdev->get_time_now().get_full_secs()){
+ std::cout << std::endl << "Success!" << std::endl << std::endl;
+ return 0;
+ } else {
+ std::cout << std::endl << "Failed!" << std::endl << std::endl
+ << "If you expected PPS to work:" << std::endl
+ << "\tsee Device App Notes for PPS level information"
+ << std::endl << std::endl;
+ return -1;
+ }
+}
diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp
index 9886000b1..3f319cf68 100644
--- a/host/examples/tx_waveforms.cpp
+++ b/host/examples/tx_waveforms.cpp
@@ -17,6 +17,7 @@
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
+#include <uhd/utils/static.hpp>
#include <uhd/usrp/simple_usrp.hpp>
#include <boost/program_options.hpp>
#include <boost/thread/thread_time.hpp> //system time
@@ -44,9 +45,16 @@ float gen_ramp(float x){
return std::fmod(x, 1)*2 - 1;
}
+#define sine_table_len 2048
+static float sine_table[sine_table_len];
+UHD_STATIC_BLOCK(gen_sine_table){
+ static const float m_pi = std::acos(float(-1));
+ for (size_t i = 0; i < sine_table_len; i++)
+ sine_table[i] = std::sin((2*m_pi*i)/sine_table_len);
+}
+
float gen_sine(float x){
- static const float two_pi = 2*std::acos(float(-1));
- return std::sin(x*two_pi);
+ return sine_table[size_t(x*sine_table_len)%sine_table_len];
}
int UHD_SAFE_MAIN(int argc, char *argv[]){
@@ -65,11 +73,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
("duration", po::value<size_t>(&total_duration)->default_value(3), "number of seconds to transmit")
("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer")
- ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of outgoing samples")
+ ("rate", po::value<double>(&rate)->default_value(1.5e6), "rate of outgoing samples")
("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz")
("ampl", po::value<float>(&ampl)->default_value(float(0.3)), "amplitude of the waveform")
("gain", po::value<float>(&gain)->default_value(float(0)), "gain for the RF chain")
- ("wave-type", po::value<std::string>(&wave_type)->default_value("SINE"), "waveform type (CONST, SQUARE, RAMP, SINE)")
+ ("wave-type", po::value<std::string>(&wave_type)->default_value("CONST"), "waveform type (CONST, SQUARE, RAMP, SINE)")
("wave-freq", po::value<double>(&wave_freq)->default_value(0), "waveform frequency in Hz")
;
po::variables_map vm;
@@ -113,6 +121,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
if (std::abs(wave_freq) > sdev->get_tx_rate()/2){
throw std::runtime_error("wave freq out of Nyquist zone");
}
+ if (sdev->get_tx_rate()/std::abs(wave_freq) > sine_table_len/2 and wave_type == "SINE"){
+ throw std::runtime_error("sine freq too small for table");
+ }
//store the generator function for the selected waveform
boost::function<float(float)> wave_gen;
diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt
index 0f1cbf2a2..2c84c0724 100644
--- a/host/include/uhd/transport/CMakeLists.txt
+++ b/host/include/uhd/transport/CMakeLists.txt
@@ -22,6 +22,7 @@ INSTALL(FILES
bounded_buffer.hpp
bounded_buffer.ipp
convert_types.hpp
+ convert_types.ipp
if_addrs.hpp
udp_simple.hpp
udp_zero_copy.hpp
diff --git a/host/include/uhd/transport/convert_types.hpp b/host/include/uhd/transport/convert_types.hpp
index a4d999240..dc7fa6c1a 100644
--- a/host/include/uhd/transport/convert_types.hpp
+++ b/host/include/uhd/transport/convert_types.hpp
@@ -21,6 +21,7 @@
#include <uhd/config.hpp>
#include <uhd/types/io_type.hpp>
#include <uhd/types/otw_type.hpp>
+#include <vector>
namespace uhd{ namespace transport{
@@ -40,6 +41,23 @@ UHD_API void convert_io_type_to_otw_type(
);
/*!
+ * Convert IO samples to OWT samples + interleave.
+ *
+ * \param io_buffs buffers containing samples
+ * \param io_type the type of these samples
+ * \param otw_buff memory to write converted samples
+ * \param otw_type the type of these samples
+ * \param nsamps_per_io_buff samples per io_buff
+ */
+UHD_API void convert_io_type_to_otw_type(
+ const std::vector<const void *> &io_buffs,
+ const io_type_t &io_type,
+ void *otw_buff,
+ const otw_type_t &otw_type,
+ size_t nsamps_per_io_buff
+);
+
+/*!
* Convert OTW samples to IO samples.
*
* \param otw_buff memory containing samples
@@ -54,6 +72,25 @@ UHD_API void convert_otw_type_to_io_type(
size_t num_samps
);
+/*!
+ * Convert OTW samples to IO samples + de-interleave.
+ *
+ * \param otw_buff memory containing samples
+ * \param otw_type the type of these samples
+ * \param io_buffs buffers to write converted samples
+ * \param io_type the type of these samples
+ * \param nsamps_per_io_buff samples per io_buff
+ */
+UHD_API void convert_otw_type_to_io_type(
+ const void *otw_buff,
+ const otw_type_t &otw_type,
+ std::vector<void *> &io_buffs,
+ const io_type_t &io_type,
+ size_t nsamps_per_io_buff
+);
+
}} //namespace
+#include <uhd/transport/convert_types.ipp>
+
#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP */
diff --git a/host/include/uhd/transport/convert_types.ipp b/host/include/uhd/transport/convert_types.ipp
new file mode 100644
index 000000000..914ca6f17
--- /dev/null
+++ b/host/include/uhd/transport/convert_types.ipp
@@ -0,0 +1,43 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP
+#define INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP
+
+UHD_INLINE void uhd::transport::convert_io_type_to_otw_type(
+ const void *io_buff, const io_type_t &io_type,
+ void *otw_buff, const otw_type_t &otw_type,
+ size_t num_samps
+){
+ std::vector<const void *> buffs(1, io_buff);
+ return uhd::transport::convert_io_type_to_otw_type(
+ buffs, io_type, otw_buff, otw_type, num_samps
+ );
+}
+
+UHD_INLINE void uhd::transport::convert_otw_type_to_io_type(
+ const void *otw_buff, const otw_type_t &otw_type,
+ void *io_buff, const io_type_t &io_type,
+ size_t num_samps
+){
+ std::vector<void *> buffs(1, io_buff);
+ return uhd::transport::convert_otw_type_to_io_type(
+ otw_buff, otw_type, buffs, io_type, num_samps
+ );
+}
+
+#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP */
diff --git a/host/include/uhd/usrp/subdev_spec.hpp b/host/include/uhd/usrp/subdev_spec.hpp
index 56aa0df20..2f32509b9 100644
--- a/host/include/uhd/usrp/subdev_spec.hpp
+++ b/host/include/uhd/usrp/subdev_spec.hpp
@@ -56,17 +56,8 @@ namespace uhd{ namespace usrp{
*
* The subdevice specification can be represented as a markup-string.
* The markup-string is a whitespace separated list of dboard:subdev pairs.
- * The "dboard:" part is optional on boards with only one daughterboard slot.
* The first pair represents the subdevice for channel zero,
* the second pair represents the subdevice for channel one, and so on.
- *
- * Examples:
- * - Use subdevice AB on daughterboard A (USRP1): "A:AB"
- * - Use subdevice A on daughterboard A for channel zero and subdevice A on daughterboard B for channel one (USRP1): "A:A B:A"
- * - Use subdevice AB (USRP2): "AB" or ":AB"
- *
- * An empty subdevice specification can be used to automatically
- * select the first subdevice on the first present daughterboard.
*/
class UHD_API subdev_spec_t : public std::vector<subdev_spec_pair_t>{
public:
diff --git a/host/lib/transport/convert_types_impl.hpp b/host/lib/transport/convert_types_impl.hpp
index fdc859883..90618dec6 100644
--- a/host/lib/transport/convert_types_impl.hpp
+++ b/host/lib/transport/convert_types_impl.hpp
@@ -42,36 +42,51 @@ typedef boost::uint32_t item32_t;
/***********************************************************************
* Convert complex short buffer to items32
**********************************************************************/
+static UHD_INLINE item32_t sc16_to_item32(sc16_t num){
+ boost::uint16_t real = num.real();
+ boost::uint16_t imag = num.imag();
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
static UHD_INLINE void sc16_to_item32_nswap(
const sc16_t *input, item32_t *output, size_t nsamps
){
- std::memcpy(output, input, nsamps*sizeof(item32_t));
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = sc16_to_item32(input[i]);
+ }
}
static UHD_INLINE void sc16_to_item32_bswap(
const sc16_t *input, item32_t *output, size_t nsamps
){
- const item32_t *item32_input = (const item32_t *)input;
for (size_t i = 0; i < nsamps; i++){
- output[i] = uhd::byteswap(item32_input[i]);
+ output[i] = uhd::byteswap(sc16_to_item32(input[i]));
}
}
/***********************************************************************
* Convert items32 buffer to complex short
**********************************************************************/
+static UHD_INLINE sc16_t item32_to_sc16(item32_t item){
+ return sc16_t(
+ boost::int16_t(item >> 16),
+ boost::int16_t(item >> 0)
+ );
+}
+
static UHD_INLINE void item32_to_sc16_nswap(
const item32_t *input, sc16_t *output, size_t nsamps
){
- std::memcpy(output, input, nsamps*sizeof(item32_t));
+ for (size_t i = 0; i < nsamps; i++){
+ output[i] = item32_to_sc16(input[i]);
+ }
}
static UHD_INLINE void item32_to_sc16_bswap(
const item32_t *input, sc16_t *output, size_t nsamps
){
- item32_t *item32_output = (item32_t *)output;
for (size_t i = 0; i < nsamps; i++){
- item32_output[i] = uhd::byteswap(input[i]);
+ output[i] = item32_to_sc16(uhd::byteswap(input[i]));
}
}
diff --git a/host/lib/transport/gen_convert_types.py b/host/lib/transport/gen_convert_types.py
index 951b634d9..adbd22868 100755
--- a/host/lib/transport/gen_convert_types.py
+++ b/host/lib/transport/gen_convert_types.py
@@ -36,7 +36,8 @@ using namespace uhd;
**********************************************************************/
UHD_INLINE boost::uint8_t get_pred(
const io_type_t &io_type,
- const otw_type_t &otw_type
+ const otw_type_t &otw_type,
+ size_t num_chans
){
boost::uint8_t pred = 0;
@@ -63,6 +64,14 @@ UHD_INLINE boost::uint8_t get_pred(
default: throw std::runtime_error("unhandled io type id");
}
+ switch(num_chans){
+ case 1: pred |= $ph.chan1_p; break;
+ case 2: pred |= $ph.chan2_p; break;
+ case 3: pred |= $ph.chan3_p; break;
+ case 4: pred |= $ph.chan4_p; break;
+ default: throw std::runtime_error("unhandled number of channels");
+ }
+
return pred;
}
@@ -70,17 +79,37 @@ UHD_INLINE boost::uint8_t get_pred(
* Convert host type to device type
**********************************************************************/
void transport::convert_io_type_to_otw_type(
- const void *io_buff, const io_type_t &io_type,
- void *otw_buff, const otw_type_t &otw_type,
- size_t num_samps
+ const std::vector<const void *> &io_buffs,
+ const io_type_t &io_type,
+ void *otw_buff,
+ const otw_type_t &otw_type,
+ size_t nsamps_per_io_buff
){
- switch(get_pred(io_type, otw_type)){
+ switch(get_pred(io_type, otw_type, io_buffs.size())){
#for $pred in range(2**$ph.nbits)
case $pred:
#set $out_type = $ph.get_dev_type($pred)
#set $in_type = $ph.get_host_type($pred)
- #set $converter = '_'.join([$in_type, 'to', $out_type, $ph.get_swap_type($pred)])
- $(converter)((const $(in_type)_t *)io_buff, ($(out_type)_t *)otw_buff, num_samps);
+ #set $num_chans = $ph.get_num_chans($pred)
+ #set $converter = '_'.join([$in_type, 'to', $out_type])
+ #if $num_chans == 1
+ $(converter)_$ph.get_swap_type($pred)(
+ reinterpret_cast<const $(in_type)_t *>(io_buffs.front()),
+ reinterpret_cast<$(out_type)_t *>(otw_buff),
+ nsamps_per_io_buff
+ );
+ #else
+ for (size_t i = 0; i < nsamps_per_io_buff; i++){
+ #for $j in range($num_chans)
+ reinterpret_cast<$(out_type)_t *>(otw_buff)[i*$num_chans + $j] =
+ #if $ph.get_swap_type($pred) == 'bswap'
+ uhd::byteswap($(converter)(reinterpret_cast<const $(in_type)_t *>(io_buffs[$j])[i]));
+ #else
+ $(converter)(reinterpret_cast<const $(in_type)_t *>(io_buffs[$j])[i]);
+ #end if
+ #end for
+ }
+ #end if
break;
#end for
}
@@ -90,17 +119,37 @@ void transport::convert_io_type_to_otw_type(
* Convert device type to host type
**********************************************************************/
void transport::convert_otw_type_to_io_type(
- const void *otw_buff, const otw_type_t &otw_type,
- void *io_buff, const io_type_t &io_type,
- size_t num_samps
+ const void *otw_buff,
+ const otw_type_t &otw_type,
+ std::vector<void *> &io_buffs,
+ const io_type_t &io_type,
+ size_t nsamps_per_io_buff
){
- switch(get_pred(io_type, otw_type)){
- #for $pred in range(4)
+ switch(get_pred(io_type, otw_type, io_buffs.size())){
+ #for $pred in range(2**$ph.nbits)
case $pred:
#set $out_type = $ph.get_host_type($pred)
#set $in_type = $ph.get_dev_type($pred)
- #set $converter = '_'.join([$in_type, 'to', $out_type, $ph.get_swap_type($pred)])
- $(converter)((const $(in_type)_t *)otw_buff, ($(out_type)_t *)io_buff, num_samps);
+ #set $num_chans = $ph.get_num_chans($pred)
+ #set $converter = '_'.join([$in_type, 'to', $out_type])
+ #if $num_chans == 1
+ $(converter)_$ph.get_swap_type($pred)(
+ reinterpret_cast<const $(in_type)_t *>(otw_buff),
+ reinterpret_cast<$(out_type)_t *>(io_buffs.front()),
+ nsamps_per_io_buff
+ );
+ #else
+ for (size_t i = 0; i < nsamps_per_io_buff; i++){
+ #for $j in range($num_chans)
+ reinterpret_cast<$(out_type)_t *>(io_buffs[$j])[i] =
+ #if $ph.get_swap_type($pred) == 'bswap'
+ $(converter)(uhd::byteswap(reinterpret_cast<const $(in_type)_t *>(otw_buff)[i*$num_chans + $j]));
+ #else
+ $(converter)(reinterpret_cast<const $(in_type)_t *>(otw_buff)[i*$num_chans + $j]);
+ #end if
+ #end for
+ }
+ #end if
break;
#end for
}
@@ -118,27 +167,43 @@ class ph:
item32_p = 0b00000
sc16_p = 0b00010
fc32_p = 0b00000
+ chan1_p = 0b00000
+ chan2_p = 0b00100
+ chan3_p = 0b01000
+ chan4_p = 0b01100
- nbits = 2 #see above
+ nbits = 4 #see above
@staticmethod
- def has(pred, flag): return (pred & flag) == flag
+ def has(pred, mask, flag): return (pred & mask) == flag
@staticmethod
def get_swap_type(pred):
- if ph.has(pred, ph.bswap_p): return 'bswap'
- if ph.has(pred, ph.nswap_p): return 'nswap'
+ mask = 0b1
+ if ph.has(pred, mask, ph.bswap_p): return 'bswap'
+ if ph.has(pred, mask, ph.nswap_p): return 'nswap'
raise NotImplementedError
@staticmethod
def get_dev_type(pred):
- if ph.has(pred, ph.item32_p): return 'item32'
+ mask = 0b0
+ if ph.has(pred, mask, ph.item32_p): return 'item32'
raise NotImplementedError
@staticmethod
def get_host_type(pred):
- if ph.has(pred, ph.sc16_p): return 'sc16'
- if ph.has(pred, ph.fc32_p): return 'fc32'
+ mask = 0b10
+ if ph.has(pred, mask, ph.sc16_p): return 'sc16'
+ if ph.has(pred, mask, ph.fc32_p): return 'fc32'
+ raise NotImplementedError
+
+ @staticmethod
+ def get_num_chans(pred):
+ mask = 0b1100
+ if ph.has(pred, mask, ph.chan1_p): return 1
+ if ph.has(pred, mask, ph.chan2_p): return 2
+ if ph.has(pred, mask, ph.chan3_p): return 3
+ if ph.has(pred, mask, ph.chan4_p): return 4
raise NotImplementedError
if __name__ == '__main__':
diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp
index 06cf91d3b..81434f054 100644
--- a/host/lib/usrp/dboard/db_dbsrx.cpp
+++ b/host/lib/usrp/dboard/db_dbsrx.cpp
@@ -205,7 +205,12 @@ dbsrx::dbsrx(ctor_args_t args) : rx_dboard_base(args){
//set the gpio directions and atr controls (identically)
this->get_iface()->set_pin_ctrl(dboard_iface::UNIT_RX, 0x0); // All unused in atr
- this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x0); // All Inputs
+ if (this->get_iface()->get_special_props().soft_clock_divider){
+ this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x1); // GPIO0 is clock
+ }
+ else{
+ this->get_iface()->set_gpio_ddr(dboard_iface::UNIT_RX, 0x0); // All Inputs
+ }
//send initial register settings
this->send_reg(0x0, 0x5);
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp
index a1664d810..5cfcdc8d3 100644
--- a/host/lib/usrp/misc_utils.cpp
+++ b/host/lib/usrp/misc_utils.cpp
@@ -164,13 +164,22 @@ static void verify_xx_subdev_spec(
//empty db name means select dboard automatically
if (pair.db_name.empty()){
if (dboard_names.size() != 1) throw std::runtime_error(
- "A daughterboard name must be provided for multi-slot boards: " + subdev_spec.to_string()
+ "A daughterboard name must be provided for multi-slot motherboards: " + subdev_spec.to_string()
);
pair.db_name == dboard_names.front();
}
uhd::assert_has(dboard_names, pair.db_name, xx_type + " dboard name");
wax::obj dboard = mboard[named_prop_t(dboard_prop, pair.db_name)];
- uhd::assert_has(dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>(), pair.sd_name, xx_type + " subdev name");
+ prop_names_t subdev_names = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>();
+
+ //empty sd name means select the subdev automatically
+ if (pair.sd_name.empty()){
+ if (subdev_names.size() != 1) throw std::runtime_error(
+ "A subdevice name must be provided for multi-subdev daughterboards: " + subdev_spec.to_string()
+ );
+ pair.sd_name == subdev_names.front();
+ }
+ uhd::assert_has(subdev_names, pair.sd_name, xx_type + " subdev name");
}
}catch(const std::exception &e){
throw std::runtime_error(str(boost::format(
diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp
index b2221e221..4791b55ce 100644
--- a/host/lib/usrp/usrp1/dboard_iface.cpp
+++ b/host/lib/usrp/usrp1/dboard_iface.cpp
@@ -49,8 +49,8 @@ public:
_codec = codec;
//init the clock rate shadows
- this->set_clock_rate(UNIT_RX, _clock->get_master_clock_freq());
- this->set_clock_rate(UNIT_TX, _clock->get_master_clock_freq());
+ this->set_clock_rate(UNIT_RX, this->get_clock_rates(UNIT_RX).front());
+ this->set_clock_rate(UNIT_TX, this->get_clock_rates(UNIT_TX).front());
}
~usrp1_dboard_iface()
@@ -134,7 +134,7 @@ void usrp1_dboard_iface::set_clock_rate(unit_t unit, double rate)
_clock_rates[unit] = rate;
if (unit == UNIT_RX && _rx_dboard_id == dbsrx_classic_id){
- size_t divider = size_t(rate/_clock->get_master_clock_freq());
+ size_t divider = size_t(_clock->get_master_clock_freq()/rate);
switch(_dboard_slot){
case usrp1_impl::DBOARD_SLOT_A:
_iface->poke32(FR_RX_A_REFCLK, (divider & 0x7f) | 0x80);
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 920c47b30..92e8bc20a 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -189,7 +189,7 @@ bool usrp1_impl::io_impl::check_underrun(usrp_ctrl::sptr ctrl_if,
if (ret < 0)
std::cerr << "USRP: underrun check failed" << std::endl;
if (underrun)
- std::cerr << "Uu";
+ std::cerr << "U" << std::flush;
send_state.underrun_poll_samp_count = 0;
}
@@ -289,7 +289,7 @@ bool usrp1_impl::io_impl::check_overrun(usrp_ctrl::sptr ctrl_if,
if (ret < 0)
std::cerr << "USRP: overrrun check failed" << std::endl;
if (overrun)
- std::cerr << "Oo";
+ std::cerr << "O" << std::flush;
recv_state.overrun_poll_samp_count = 0;
}
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index 8ad148274..a18b697fb 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -21,6 +21,8 @@
#include "usrp_spi_defs.h"
#include <uhd/transport/usb_control.hpp>
#include <uhd/usrp/device_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/utils/warning.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/images.hpp>
@@ -54,9 +56,19 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs;
//extract the firmware path for the USRP1
- std::string usrp1_fw_image = find_image_path(
- hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx"
- );
+ std::string usrp1_fw_image;
+ try{
+ usrp1_fw_image = find_image_path(
+ hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx"
+ );
+ }
+ catch(const std::exception &e){
+ uhd::print_warning(
+ "Could not locate USRP1 firmware.\n"
+ "Please install the images package.\n"
+ );
+ return usrp1_addrs;
+ }
std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
boost::uint16_t vid = hint.has_key("uninit") ? FX2_VENDOR_ID : USRP1_VENDOR_ID;
@@ -173,6 +185,10 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport,
//turn on the transmitter
_ctrl_transport->usrp_tx_enable(true);
+
+ //init the subdev specs
+ this->mboard_set(MBOARD_PROP_RX_SUBDEV_SPEC, subdev_spec_t());
+ this->mboard_set(MBOARD_PROP_TX_SUBDEV_SPEC, subdev_spec_t());
}
usrp1_impl::~usrp1_impl(void){
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 9e29edd82..4e883cf81 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -113,7 +113,7 @@ void usrp2_impl::io_impl::recv_pirate_loop(
metadata.event_code = vrt_packet_handler::get_context_code<async_metadata_t::event_code_t>(vrt_hdr, if_packet_info);
//print the famous U, and push the metadata into the message queue
- if (metadata.event_code & underflow_flags) std::cerr << "U";
+ if (metadata.event_code & underflow_flags) std::cerr << "U" << std::flush;
async_msg_fifo->push_with_pop_on_full(metadata);
continue;
}
@@ -121,7 +121,7 @@ void usrp2_impl::io_impl::recv_pirate_loop(
//handle the packet count / sequence number
if (if_packet_info.packet_count != next_packet_seq){
//std::cerr << "S" << (if_packet_info.packet_count - next_packet_seq)%16;
- std::cerr << "O"; //report overflow (drops in the kernel)
+ std::cerr << "O" << std::flush; //report overflow (drops in the kernel)
}
next_packet_seq = (if_packet_info.packet_count+1)%16;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index d5785f326..0b9f8ee83 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -69,6 +69,11 @@ usrp2_mboard_impl::usrp2_mboard_impl(
_allowed_decim_and_interp_rates.push_back(i);
}
+ //Issue a stop streaming command (in case it was left running).
+ //Since this command is issued before the networking is setup,
+ //most if not all junk packets will never make it to the socket.
+ this->issue_ddc_stream_cmd(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
+
//init the rx control registers
_iface->poke32(U2_REG_RX_CTRL_NSAMPS_PER_PKT, _io_helper.get_max_recv_samps_per_packet());
_iface->poke32(U2_REG_RX_CTRL_NCHANNELS, 1);
@@ -107,11 +112,6 @@ usrp2_mboard_impl::usrp2_mboard_impl(
//set default subdev specs
(*this)[MBOARD_PROP_RX_SUBDEV_SPEC] = subdev_spec_t();
(*this)[MBOARD_PROP_TX_SUBDEV_SPEC] = subdev_spec_t();
-
- //Issue a stop streaming command (in case it was left running).
- //Since this command is issued before the networking is setup,
- //most if not all junk packets will never make it to the socket.
- this->issue_ddc_stream_cmd(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
}
usrp2_mboard_impl::~usrp2_mboard_impl(void){
diff --git a/host/test/convert_types_test.cpp b/host/test/convert_types_test.cpp
index d132a708b..2148302b6 100644
--- a/host/test/convert_types_test.cpp
+++ b/host/test/convert_types_test.cpp
@@ -27,7 +27,7 @@
using namespace uhd;
//typedefs for complex types
-typedef std::complex<boost::uint16_t> sc16_t;
+typedef std::complex<boost::int16_t> sc16_t;
typedef std::complex<float> fc32_t;
//extract pointer to POD since using &vector.front() throws in MSVC
@@ -158,3 +158,85 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){
test_convert_types_fc32(nsamps, io_type, otw_type);
}
}
+
+/***********************************************************************
+ * Test float to short conversion loopback
+ **********************************************************************/
+BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){
+ io_type_t io_type_in(io_type_t::COMPLEX_FLOAT32);
+ io_type_t io_type_out(io_type_t::COMPLEX_INT16);
+
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_NATIVE;
+ otw_type.width = 16;
+
+ const size_t nsamps = 13;
+ std::vector<fc32_t> input(nsamps);
+ BOOST_FOREACH(fc32_t &in, input) in = fc32_t(
+ (std::rand()/float(RAND_MAX/2)) - 1,
+ (std::rand()/float(RAND_MAX/2)) - 1
+ );
+
+ //convert float to dev
+ std::vector<boost::uint32_t> tmp(nsamps);
+ transport::convert_io_type_to_otw_type(
+ pod2ptr(input), io_type_in,
+ pod2ptr(tmp), otw_type,
+ nsamps
+ );
+
+ //convert dev to short
+ std::vector<sc16_t> output(nsamps);
+ transport::convert_otw_type_to_io_type(
+ pod2ptr(tmp), otw_type,
+ pod2ptr(output), io_type_out,
+ nsamps
+ );
+
+ //test that the inputs and outputs match
+ for (size_t i = 0; i < nsamps; i++){
+ BOOST_CHECK_CLOSE_FRACTION(input[i].real(), output[i].real()/float(32767), float(0.01));
+ BOOST_CHECK_CLOSE_FRACTION(input[i].imag(), output[i].imag()/float(32767), float(0.01));
+ }
+}
+
+/***********************************************************************
+ * Test short to float conversion loopback
+ **********************************************************************/
+BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){
+ io_type_t io_type_in(io_type_t::COMPLEX_INT16);
+ io_type_t io_type_out(io_type_t::COMPLEX_FLOAT32);
+
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_NATIVE;
+ otw_type.width = 16;
+
+ const size_t nsamps = 13;
+ std::vector<sc16_t> input(nsamps);
+ BOOST_FOREACH(sc16_t &in, input) in = sc16_t(
+ std::rand()-(RAND_MAX/2),
+ std::rand()-(RAND_MAX/2)
+ );
+
+ //convert short to dev
+ std::vector<boost::uint32_t> tmp(nsamps);
+ transport::convert_io_type_to_otw_type(
+ pod2ptr(input), io_type_in,
+ pod2ptr(tmp), otw_type,
+ nsamps
+ );
+
+ //convert dev to float
+ std::vector<fc32_t> output(nsamps);
+ transport::convert_otw_type_to_io_type(
+ pod2ptr(tmp), otw_type,
+ pod2ptr(output), io_type_out,
+ nsamps
+ );
+
+ //test that the inputs and outputs match
+ for (size_t i = 0; i < nsamps; i++){
+ BOOST_CHECK_CLOSE_FRACTION(input[i].real()/float(32767), output[i].real(), float(0.01));
+ BOOST_CHECK_CLOSE_FRACTION(input[i].imag()/float(32767), output[i].imag(), float(0.01));
+ }
+}