diff options
author | Lane Kolbly <lane.kolbly@ni.com> | 2021-10-29 12:10:56 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-11-03 06:04:19 -0700 |
commit | 905667d69ae99a81716c9723ea429fdbf76ea6c4 (patch) | |
tree | 1c3e7ea1e9a844bbf3efaecd03b0804ef4c6f850 /host/examples | |
parent | c23dc3b0122a46353810d1ccbe98c08b080850e8 (diff) | |
download | uhd-905667d69ae99a81716c9723ea429fdbf76ea6c4.tar.gz uhd-905667d69ae99a81716c9723ea429fdbf76ea6c4.tar.bz2 uhd-905667d69ae99a81716c9723ea429fdbf76ea6c4.zip |
example: gpio: Separate bank and port arguments
"bank" refers to what the radio control sees, and "port" refers to what
the user looking at the physical device sees. For example, on X410 each
radio control only has a single (24-bit) output, which can be routed
to either of two ports.
Diffstat (limited to 'host/examples')
-rw-r--r-- | host/examples/gpio.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/host/examples/gpio.cpp b/host/examples/gpio.cpp index d4a188c66..417234881 100644 --- a/host/examples/gpio.cpp +++ b/host/examples/gpio.cpp @@ -117,7 +117,8 @@ std::string to_bit_string(uint32_t val, const size_t num_bits) return out; } -void output_reg_values(const std::string bank, +void output_reg_values(const std::string& bank, + const std::string& port, const uhd::usrp::multi_usrp::sptr& usrp, const size_t num_bits) { @@ -136,7 +137,7 @@ void output_reg_values(const std::string bank, // GPIO Src - get_gpio_src() not supported for all devices try { - const auto gpio_src = usrp->get_gpio_src(bank); + const auto gpio_src = usrp->get_gpio_src(port); std::cout << boost::format("%10s:") % "SRC"; for (auto src : gpio_src) { std::cout << " " << src; @@ -156,6 +157,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) std::string cpu, otw; double rx_rate, tx_rate, dwell; std::string gpio; + std::string port; size_t num_bits; std::string src_str; std::string ctrl_str; @@ -180,6 +182,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) ("tx_rate", po::value<double>(&tx_rate)->default_value(GPIO_DEFAULT_TX_RATE), "tx sample rate") ("dwell", po::value<double>(&dwell)->default_value(GPIO_DEFAULT_DWELL_TIME), "dwell time in seconds for each test case") ("bank", po::value<std::string>(&gpio)->default_value(GPIO_DEFAULT_GPIO), "name of gpio bank") + ("port", po::value<std::string>(&port)->default_value(""), "name of gpio port. If not specified, defaults to the GPIO bank") ("bits", po::value<size_t>(&num_bits)->default_value(GPIO_DEFAULT_NUM_BITS), "number of bits in gpio bank") ("bitbang", "single test case where user sets values for CTRL, DDR, and OUT registers") ("src", po::value<std::string>(&src_str), "GPIO SRC reg value") @@ -197,6 +200,11 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) return ~0; } + // Handle if the port is unspecified + if (port.empty()) { + port = gpio; + } + // create a usrp device std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % args @@ -227,7 +235,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) // print out initial unconfigured state of GPIO std::cout << "Initial GPIO values:" << std::endl; - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); // configure GPIO registers uint32_t ddr = strtoul(ddr_str.c_str(), NULL, 0); @@ -271,7 +279,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) typedef boost::char_separator<char> separator; boost::tokenizer<separator> tokens(src_str, separator(" ")); std::copy(tokens.begin(), tokens.end(), std::back_inserter(gpio_src)); - usrp->set_gpio_src(gpio, gpio_src); + usrp->set_gpio_src(port, gpio_src); } // set data direction register (DDR) @@ -291,7 +299,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) // print out initial state of FP GPIO std::cout << "\nConfigured GPIO values:" << std::endl; - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); std::cout << std::endl; // set up streams @@ -353,7 +361,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) std::cout << "pass:" << std::endl; else std::cout << "fail:" << std::endl; - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); // restore DDR value usrp->set_gpio_attr(gpio, "DDR", ddr, mask); } @@ -396,7 +404,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) } else { std::cout << "pass:" << std::endl; } - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); usrp->set_gpio_attr(gpio, "OUT", 0, GPIO_BIT(4)); if (stop_signal_called) break; @@ -423,7 +431,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) } else { std::cout << "pass:" << std::endl; } - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); rx_stream->issue_stream_cmd( uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); // clear out any data left in the rx stream @@ -458,7 +466,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) } else { std::cout << "pass:" << std::endl; } - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); tx_md.end_of_burst = true; try { tx_stream->send(tx_buffs, nsamps_per_buff, tx_md, timeout); @@ -513,7 +521,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) } else { std::cout << "pass:" << std::endl; } - output_reg_values(gpio, usrp, num_bits); + output_reg_values(gpio, port, usrp, num_bits); } std::cout << std::endl; |