aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples/rfnoc-example/apps/init_gain_block.cpp
diff options
context:
space:
mode:
authorSugandha Gupta <sugandha.gupta@ettus.com>2019-10-15 11:52:46 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 12:21:32 -0800
commita801d6b046743140e9a50c7788dd17dd71f5540a (patch)
tree58d164e1b4cb2a8d871ca532287699f3912ae3d8 /host/examples/rfnoc-example/apps/init_gain_block.cpp
parent2a7e69d862f661075b98bab19e58d958c28a9af8 (diff)
downloaduhd-a801d6b046743140e9a50c7788dd17dd71f5540a.tar.gz
uhd-a801d6b046743140e9a50c7788dd17dd71f5540a.tar.bz2
uhd-a801d6b046743140e9a50c7788dd17dd71f5540a.zip
examples: Add example out-of-tree module for RFNoC modules
This subdirectory is its own, self-contained project. It is supposed to work against the UHD version it is shipped with. Co-Authored-By: Martin Braun <martin.braun@ettus.com> Co-Authored-By: Wade Fife <wade.fife@ni.com>
Diffstat (limited to 'host/examples/rfnoc-example/apps/init_gain_block.cpp')
-rw-r--r--host/examples/rfnoc-example/apps/init_gain_block.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/host/examples/rfnoc-example/apps/init_gain_block.cpp b/host/examples/rfnoc-example/apps/init_gain_block.cpp
new file mode 100644
index 000000000..f9de5f92c
--- /dev/null
+++ b/host/examples/rfnoc-example/apps/init_gain_block.cpp
@@ -0,0 +1,77 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+// Example application to show how to write applications that depend on both UHD
+// and out-of-tree RFNoC modules.
+//
+// It will see if a USRP is runnging the gain block, if so, it will test to see
+// if it can change the gain.
+
+#include <uhd/exception.hpp>
+#include <uhd/rfnoc_graph.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <rfnoc/example/gain_block_control.hpp>
+#include <boost/program_options.hpp>
+
+namespace po = boost::program_options;
+
+int UHD_SAFE_MAIN(int argc, char* argv[])
+{
+ std::string args;
+
+ // setup the program options
+ po::options_description desc("Allowed options");
+ // clang-format off
+ desc.add_options()
+ ("help", "help message")
+ ("args", po::value<std::string>(&args)->default_value(""), "USRP device address args")
+ ;
+ // clang-format on
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ // print the help message
+ if (vm.count("help")) {
+ std::cout << "Init RFNoC gain block " << desc << std::endl;
+ std::cout << std::endl
+ << "This application attempts to find a gain block in a USRP "
+ "and tries to peek/poke registers..\n"
+ << std::endl;
+ return EXIT_SUCCESS;
+ }
+
+ // Create RFNoC graph object:
+ auto graph = uhd::rfnoc::rfnoc_graph::make(args);
+
+ // Verify we have a gain block:
+ auto gain_blocks = graph->find_blocks<rfnoc::example::gain_block_control>("");
+ if (gain_blocks.empty()) {
+ std::cout << "No gain block found." << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ auto gain_block =
+ graph->get_block<rfnoc::example::gain_block_control>(gain_blocks.front());
+ if (!gain_block) {
+ std::cout << "ERROR: Failed to extract block controller!" << std::endl;
+ return EXIT_FAILURE;
+ }
+ constexpr uint32_t new_gain_value = 42;
+ gain_block->set_gain_value(new_gain_value);
+ const uint32_t gain_value_read = gain_block->get_gain_value();
+
+ if (gain_value_read != new_gain_value) {
+ std::cout << "ERROR: Readback of gain value not working! "
+ << "Expected: " << new_gain_value << " Read: " << gain_value_read
+ << std::endl;
+ return EXIT_FAILURE;
+ } else {
+ std::cout << "Gain value read/write loopback successful!" << std::endl;
+ }
+
+ return EXIT_SUCCESS;
+}