diff options
Diffstat (limited to 'host/utils/uhd_cal_rx_iq_balance.cpp')
-rw-r--r-- | host/utils/uhd_cal_rx_iq_balance.cpp | 35 |
1 files changed, 28 insertions, 7 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 |