aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils
diff options
context:
space:
mode:
authorNicolas Cuervo <nicolas.cuervo@ettus.com>2016-10-03 16:39:30 -0700
committerMartin Braun <martin.braun@ettus.com>2018-04-18 15:05:22 -0700
commita8c74853f9bc73a796c553fc7cebb14266775e59 (patch)
tree5f1294e4c1672ebb137c15054759dd188cfb4af7 /host/utils
parent0e909a2a9d2432c1f935f79953e78663b4129132 (diff)
downloaduhd-a8c74853f9bc73a796c553fc7cebb14266775e59.tar.gz
uhd-a8c74853f9bc73a796c553fc7cebb14266775e59.tar.bz2
uhd-a8c74853f9bc73a796c553fc7cebb14266775e59.zip
cal_utils: logic to handle eventual U's during calibration
For every frequency point, the cal utils will detect underruns and retry a calibration measurement up to 10 times before failing.
Diffstat (limited to 'host/utils')
-rw-r--r--host/utils/uhd_cal_rx_iq_balance.cpp35
-rw-r--r--host/utils/uhd_cal_tx_dc_offset.cpp32
-rw-r--r--host/utils/uhd_cal_tx_iq_balance.cpp34
-rw-r--r--host/utils/usrp_cal_utils.hpp20
4 files changed, 99 insertions, 22 deletions
diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp
index 88ec77a0a..254ea9de7 100644
--- a/host/utils/uhd_cal_rx_iq_balance.cpp
+++ b/host/utils/uhd_cal_rx_iq_balance.cpp
@@ -26,14 +26,10 @@ namespace po = boost::program_options;
/***********************************************************************
* Transmit thread
**********************************************************************/
-static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_ampl)
+static void tx_thread(uhd::tx_streamer::sptr tx_stream, const double tx_wave_ampl)
{
uhd::set_thread_priority_safe();
- //create a transmit streamer
- uhd::stream_args_t stream_args("fc32"); //complex floats
- uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
-
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
@@ -138,9 +134,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+ //create a transmit streamer
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+
//create a transmitter thread
boost::thread_group threads;
- threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_ampl));
+ threads.create_thread(boost::bind(&tx_thread, tx_stream, tx_wave_ampl));
//re-usable buffer for samples
std::vector<samp_type> buff;
@@ -175,6 +174,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
std::cout << boost::format("Calibration frequency range: %d MHz -> %d MHz") % (freq_start/1e6) % (freq_stop/1e6) << std::endl;
+ size_t tx_error_count = 0;
for (double rx_lo_i = freq_start; rx_lo_i <= freq_stop; rx_lo_i += freq_step)
{
const double rx_lo = tune_rx_and_tx(usrp, rx_lo_i, tx_offset);
@@ -217,6 +217,24 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
//receive some samples
capture_samples(usrp, rx_stream, buff, nsamps);
+ //check for TX errors in the current captured iteration
+ if (has_tx_error(tx_stream)){
+ if (vm.count("verbose")) {
+ std::cout
+ << "[WARNING] TX error detected! "
+ << "Repeating current iteration"
+ << std::endl;
+ }
+ // Undo the correction step:
+ ampl_corr -= ampl_corr_step;
+ tx_error_count++;
+ if (tx_error_count >= MAX_NUM_TX_ERRORS) {
+ throw uhd::runtime_error(
+ "Too many TX errors. Aborting calibration."
+ );
+ }
+ continue;
+ }
const double tone_dbrms = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate);
const double imag_dbrms = compute_tone_dbrms(buff, bb_imag_freq/actual_rx_rate);
const double suppression = tone_dbrms - imag_dbrms;
@@ -252,7 +270,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
else
std::cout << "." << std::flush;
}
- }
+
+ // Reset underrun counts, start a new counter for the next frequency
+ tx_error_count = 0;
+ } // end for each frequency loop
std::cout << std::endl;
//stop the transmitter
diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp
index 0a11cc223..4adea9c2a 100644
--- a/host/utils/uhd_cal_tx_dc_offset.cpp
+++ b/host/utils/uhd_cal_tx_dc_offset.cpp
@@ -24,17 +24,13 @@ namespace po = boost::program_options;
/***********************************************************************
* Transmit thread
**********************************************************************/
-static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_freq, const double tx_wave_ampl)
+static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, uhd::tx_streamer::sptr tx_stream, const double tx_wave_freq, const double tx_wave_ampl)
{
uhd::set_thread_priority_safe();
// set max TX gain
usrp->set_tx_gain(usrp->get_tx_gain_range().stop());
- //create a transmit streamer
- uhd::stream_args_t stream_args("fc32"); //complex floats
- uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
-
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
@@ -146,9 +142,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+ //create a transmit streamer
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+
//create a transmitter thread
boost::thread_group threads;
- threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
+ threads.create_thread(boost::bind(&tx_thread, usrp, tx_stream, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
std::vector<samp_type> buff;
@@ -186,6 +185,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
//set RX gain
usrp->set_rx_gain(0);
+ size_t tx_error_count = 0;
for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step)
{
const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset);
@@ -224,6 +224,22 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
//receive some samples
capture_samples(usrp, rx_stream, buff, nsamps);
+ //check for TX errors in the current captured iteration
+ if (has_tx_error(tx_stream)){
+ std::cout
+ << "[WARNING] TX error detected! "
+ << "Repeating current iteration"
+ << std::endl;
+ // Undo the Q correction step
+ q_corr -= q_corr_step;
+ tx_error_count++;
+ if (tx_error_count >= MAX_NUM_TX_ERRORS) {
+ throw uhd::runtime_error(
+ "Too many TX errors. Aborting calibration."
+ );
+ }
+ continue;
+ }
const double dc_dbrms = compute_tone_dbrms(buff, bb_dc_freq/actual_rx_rate);
if (dc_dbrms < best_dc_dbrms)
@@ -258,7 +274,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
std::cout << "." << std::flush;
}
- }
+ // Reset underrun counts, start a new counter for the next frequency
+ tx_error_count = 0;
+ } // end for each frequency loop
std::cout << std::endl;
diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp
index da6631dc4..3cc7b80c7 100644
--- a/host/utils/uhd_cal_tx_iq_balance.cpp
+++ b/host/utils/uhd_cal_tx_iq_balance.cpp
@@ -21,17 +21,13 @@ namespace po = boost::program_options;
/***********************************************************************
* Transmit thread
**********************************************************************/
-static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_freq, const double tx_wave_ampl)
+static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, uhd::tx_streamer::sptr tx_stream, const double tx_wave_freq, const double tx_wave_ampl)
{
uhd::set_thread_priority_safe();
// set max TX gain
usrp->set_tx_gain(usrp->get_tx_gain_range().stop());
- //create a transmit streamer
- uhd::stream_args_t stream_args("fc32"); //complex floats
- uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
-
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
@@ -144,9 +140,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+ //create a transmit streamer
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+
//create a transmitter thread
boost::thread_group threads;
- threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
+ threads.create_thread(boost::bind(&tx_thread, usrp, tx_stream, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
std::vector<samp_type> buff;
@@ -181,8 +180,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
std::cout << boost::format("Calibration frequency range: %d MHz -> %d MHz") % (freq_start/1e6) % (freq_stop/1e6) << std::endl;
+ size_t tx_error_count = 0;
for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step)
{
+
const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset);
//frequency constants for this tune event
@@ -223,6 +224,22 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
//receive some samples
capture_samples(usrp, rx_stream, buff, nsamps);
+ //check for TX errors in the current captured iteration
+ if (has_tx_error(tx_stream)){
+ std::cout
+ << "[WARNING] TX error detected! "
+ << "Repeating current iteration"
+ << std::endl;
+ // Undo ampl corr step
+ ampl_corr -= ampl_corr_step;
+ tx_error_count++;
+ if (tx_error_count >= MAX_NUM_TX_ERRORS) {
+ throw uhd::runtime_error(
+ "Too many TX errors. Aborting calibration."
+ );
+ }
+ continue;
+ }
const double tone_dbrms = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate);
const double imag_dbrms = compute_tone_dbrms(buff, bb_imag_freq/actual_rx_rate);
const double suppression = tone_dbrms - imag_dbrms;
@@ -235,7 +252,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
}
}
}
-
phase_corr_start = best_phase_corr - phase_corr_step;
phase_corr_stop = best_phase_corr + phase_corr_step;
phase_corr_step = (phase_corr_stop - phase_corr_start)/(num_search_steps+1);
@@ -243,7 +259,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
ampl_corr_stop = best_ampl_corr + ampl_corr_step;
ampl_corr_step = (ampl_corr_stop - ampl_corr_start)/(num_search_steps+1);
}
-
if (best_suppression > initial_suppression) //keep result
{
result_t result;
@@ -258,6 +273,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[])
else
std::cout << "." << std::flush;
}
+
+ // Reset underrun counts, start a new counter for the next frequency
+ tx_error_count = 0;
}
std::cout << std::endl;
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp
index 367ec44ab..88fedcbd4 100644
--- a/host/utils/usrp_cal_utils.hpp
+++ b/host/utils/usrp_cal_utils.hpp
@@ -35,6 +35,7 @@ static const size_t num_search_steps = 5;
static const double default_precision = 0.0001;
static const double default_freq_step = 7.3e6;
static const size_t default_fft_bin_size = 1000;
+static constexpr size_t MAX_NUM_TX_ERRORS = 10;
/***********************************************************************
* Set standard defaults for devices
@@ -375,3 +376,22 @@ UHD_INLINE void set_optimal_rx_gain(
usrp->set_rx_gain(rx_gain);
}
+
+/*! Returns true if any error on the TX stream has occured
+ */
+bool has_tx_error(uhd::tx_streamer::sptr tx_stream)
+{
+ uhd::async_metadata_t async_md;
+ if (!tx_stream->recv_async_msg(async_md, 0.0)) {
+ return false;
+ }
+
+ return async_md.event_code & (0
+ // Any of these errors are considered a problematic TX error:
+ | uhd::async_metadata_t::EVENT_CODE_UNDERFLOW
+ | uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR
+ | uhd::async_metadata_t::EVENT_CODE_TIME_ERROR
+ | uhd::async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET
+ | uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST
+ );
+}