aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils/uhd_cal_tx_dc_offset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/utils/uhd_cal_tx_dc_offset.cpp')
-rw-r--r--host/utils/uhd_cal_tx_dc_offset.cpp32
1 files changed, 25 insertions, 7 deletions
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;