summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-11-15 17:16:31 -0800
committerJosh Blum <josh@joshknows.com>2011-11-15 17:16:31 -0800
commit075e6a9788856d6951df42349afef7816852ca68 (patch)
tree236f6544592681665766e69c2578150d34f399e8
parent18abd4dbbf29ec9372bdd2ee83288fc94c20534c (diff)
downloaduhd-075e6a9788856d6951df42349afef7816852ca68.tar.gz
uhd-075e6a9788856d6951df42349afef7816852ca68.tar.bz2
uhd-075e6a9788856d6951df42349afef7816852ca68.zip
uhd: more common code in cal utils
-rw-r--r--host/utils/uhd_cal_rx_iq_balance.cpp39
-rw-r--r--host/utils/uhd_cal_tx_dc_offset.cpp39
-rw-r--r--host/utils/uhd_cal_tx_iq_balance.cpp39
-rw-r--r--host/utils/usrp_cal_utils.hpp53
4 files changed, 69 insertions, 101 deletions
diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp
index a05df60b2..ee6b28abc 100644
--- a/host/utils/uhd_cal_rx_iq_balance.cpp
+++ b/host/utils/uhd_cal_rx_iq_balance.cpp
@@ -89,33 +89,11 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double rx_l
}
/***********************************************************************
- * Data capture routine
- **********************************************************************/
-static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr rx_stream, std::vector<std::complex<float> > &buff){
- uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
- stream_cmd.num_samps = buff.size();
- stream_cmd.stream_now = true;
- usrp->issue_stream_cmd(stream_cmd);
- uhd::rx_metadata_t md;
- const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
-
- //validate the received data
- if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
- throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
- }
- if (num_rx_samps != buff.size()){
- throw std::runtime_error("did not get all the samples requested");
- }
-}
-
-/***********************************************************************
* Main
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_ampl, tx_offset;
+ double tx_wave_ampl, tx_offset;
double freq_start, freq_stop, freq_step;
size_t nsamps;
@@ -124,7 +102,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("help", "help message")
("verbose", "enable some verbose")
("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]")
- ("rate", po::value<double>(&rate)->default_value(12.5e6), "RX and TX sample rate in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("tx_offset", po::value<double>(&tx_offset)->default_value(.9344e6), "TX LO offset from the RX LO in Hz")
("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)")
@@ -158,12 +135,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
- //set optimum gain settings
- set_optimum_gain(usrp);
-
- //set the sample rates
- usrp->set_rx_rate(rate);
- usrp->set_tx_rate(rate);
+ //set optimum defaults
+ set_optimum_defaults(usrp);
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
@@ -174,7 +147,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff(nsamps);
+ std::vector<std::complex<float> > buff;
//store the results here
std::vector<result_t> results;
@@ -194,7 +167,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//capture initial uncorrected value
usrp->set_rx_iq_balance(std::polar<double>(1.0, 0.0));
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
const double initial_suppression = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate) - compute_tone_dbrms(buff, bb_imag_freq/actual_rx_rate);
//bounds and results from searching
@@ -215,7 +188,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_iq_balance(correction);
//receive some samples
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
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);
diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp
index ed1b85bb3..5ef9f823c 100644
--- a/host/utils/uhd_cal_tx_dc_offset.cpp
+++ b/host/utils/uhd_cal_tx_dc_offset.cpp
@@ -90,33 +90,11 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l
}
/***********************************************************************
- * Data capture routine
- **********************************************************************/
-static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr rx_stream, std::vector<std::complex<float> > &buff){
- uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
- stream_cmd.num_samps = buff.size();
- stream_cmd.stream_now = true;
- usrp->issue_stream_cmd(stream_cmd);
- uhd::rx_metadata_t md;
- const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
-
- //validate the received data
- if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
- throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
- }
- if (num_rx_samps != buff.size()){
- throw std::runtime_error("did not get all the samples requested");
- }
-}
-
-/***********************************************************************
* Main
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_freq, tx_wave_ampl, rx_offset;
+ double tx_wave_freq, tx_wave_ampl, rx_offset;
double freq_start, freq_stop, freq_step;
size_t nsamps;
@@ -125,7 +103,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("help", "help message")
("verbose", "enable some verbose")
("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]")
- ("rate", po::value<double>(&rate)->default_value(12.5e6), "RX and TX sample rate in Hz")
("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz")
@@ -160,12 +137,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
- //set optimum gain settings
- set_optimum_gain(usrp);
-
- //set the sample rates
- usrp->set_rx_rate(rate);
- usrp->set_tx_rate(rate);
+ //set optimum defaults
+ set_optimum_defaults(usrp);
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
@@ -176,7 +149,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff(nsamps);
+ std::vector<std::complex<float> > buff;
//store the results here
std::vector<result_t> results;
@@ -195,7 +168,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//capture initial uncorrected value
usrp->set_tx_dc_offset(std::complex<double>(0, 0));
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
const double initial_dc_dbrms = compute_tone_dbrms(buff, bb_dc_freq/actual_rx_rate);
//bounds and results from searching
@@ -215,7 +188,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_tx_dc_offset(correction);
//receive some samples
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
const double dc_dbrms = compute_tone_dbrms(buff, bb_dc_freq/actual_rx_rate);
diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp
index 8b49ef170..d7851424a 100644
--- a/host/utils/uhd_cal_tx_iq_balance.cpp
+++ b/host/utils/uhd_cal_tx_iq_balance.cpp
@@ -90,33 +90,11 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l
}
/***********************************************************************
- * Data capture routine
- **********************************************************************/
-static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr rx_stream, std::vector<std::complex<float> > &buff){
- uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
- stream_cmd.num_samps = buff.size();
- stream_cmd.stream_now = true;
- usrp->issue_stream_cmd(stream_cmd);
- uhd::rx_metadata_t md;
- const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
-
- //validate the received data
- if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
- throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
- }
- if (num_rx_samps != buff.size()){
- throw std::runtime_error("did not get all the samples requested");
- }
-}
-
-/***********************************************************************
* Main
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_freq, tx_wave_ampl, rx_offset;
+ double tx_wave_freq, tx_wave_ampl, rx_offset;
double freq_start, freq_stop, freq_step;
size_t nsamps;
@@ -125,7 +103,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("help", "help message")
("verbose", "enable some verbose")
("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]")
- ("rate", po::value<double>(&rate)->default_value(12.5e6), "RX and TX sample rate in Hz")
("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz")
@@ -160,12 +137,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
- //set optimum gain settings
- set_optimum_gain(usrp);
-
- //set the sample rates
- usrp->set_rx_rate(rate);
- usrp->set_tx_rate(rate);
+ //set optimum defaults
+ set_optimum_defaults(usrp);
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
@@ -176,7 +149,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
//re-usable buffer for samples
- std::vector<std::complex<float> > buff(nsamps);
+ std::vector<std::complex<float> > buff;
//store the results here
std::vector<result_t> results;
@@ -196,7 +169,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//capture initial uncorrected value
usrp->set_tx_iq_balance(std::polar<double>(1.0, 0.0));
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
const double initial_suppression = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate) - compute_tone_dbrms(buff, bb_imag_freq/actual_rx_rate);
//bounds and results from searching
@@ -217,7 +190,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_tx_iq_balance(correction);
//receive some samples
- capture_samples(usrp, rx_stream, buff);
+ capture_samples(usrp, rx_stream, buff, nsamps);
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);
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp
index 3058cd928..6417b5d8b 100644
--- a/host/utils/usrp_cal_utils.hpp
+++ b/host/utils/usrp_cal_utils.hpp
@@ -43,10 +43,25 @@ static const double default_freq_step = 7.3e6;
static const size_t default_num_samps = 10000;
/***********************************************************************
- * Determine gain settings
+ * Set standard defaults for devices
**********************************************************************/
-static inline void set_optimum_gain(uhd::usrp::multi_usrp::sptr usrp){
+static inline void set_optimum_defaults(uhd::usrp::multi_usrp::sptr usrp){
uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
+
+ const uhd::fs_path mb_path = "/mboards/0";
+ const std::string mb_name = tree->access<std::string>(mb_path / "name").get();
+ if (mb_name.find("USRP2") != std::string::npos){
+ usrp->set_tx_rate(12.5e6);
+ usrp->set_rx_rate(12.5e6);
+ }
+ else if (mb_name.find("B100") != std::string::npos){
+ usrp->set_tx_rate(4e6);
+ usrp->set_rx_rate(4e6);
+ }
+ else{
+ throw std::runtime_error("self-calibration is not supported for this hardware");
+ }
+
const uhd::fs_path tx_fe_path = "/mboards/0/dboards/A/tx_frontends/0";
const std::string tx_name = tree->access<std::string>(tx_fe_path / "name").get();
if (tx_name.find("WBX") != std::string::npos or tx_name.find("SBX") != std::string::npos){
@@ -166,3 +181,37 @@ static void store_results(
std::cout << "wrote cal data to " << cal_data_path << std::endl;
}
+
+/***********************************************************************
+ * Data capture routine
+ **********************************************************************/
+static void capture_samples(
+ uhd::usrp::multi_usrp::sptr usrp,
+ uhd::rx_streamer::sptr rx_stream,
+ std::vector<std::complex<float> > &buff,
+ const size_t nsamps_requested
+){
+ buff.resize(nsamps_requested);
+ uhd::rx_metadata_t md;
+
+ uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
+ stream_cmd.num_samps = buff.size();
+ stream_cmd.stream_now = true;
+ usrp->issue_stream_cmd(stream_cmd);
+ const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
+
+ //validate the received data
+ if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
+ throw std::runtime_error(str(boost::format(
+ "Unexpected error code 0x%x"
+ ) % md.error_code));
+ }
+ //we can live if all the data didnt come in
+ if (num_rx_samps > buff.size()/2){
+ buff.resize(num_rx_samps);
+ return;
+ }
+ if (num_rx_samps != buff.size()){
+ throw std::runtime_error("did not get all the samples requested");
+ }
+}