From ba950f8d6e9c8dd55ba3784b15d48985745f03d1 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 27 May 2022 16:16:47 +0200 Subject: fixup! examples: gpio: Refactor example The refactoring changed the behaviour of --bitbang: before, it would terminate after one readback unless --repeat was specified, in which case it would require a Ctrl-C (SIGINT). After the refactoring, it always required a SIGINT. This changes the behaviour back to prior to 727141d, and will now only read back once, unless --repeat is provided. This also fixes the bitbang devtest, which would go on indefinitely. --- host/examples/gpio.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'host') diff --git a/host/examples/gpio.cpp b/host/examples/gpio.cpp index 730cf905f..01648c187 100644 --- a/host/examples/gpio.cpp +++ b/host/examples/gpio.cpp @@ -185,7 +185,8 @@ void run_bitbang_test(uhd::usrp::multi_usrp::sptr usrp, const uint32_t out, const uint32_t mask, const uint32_t num_bits, - const std::chrono::milliseconds dwell_time) + const std::chrono::milliseconds dwell_time, + const bool repeat) { // Set all pins to "GPIO", and DDR/OUT to whatever the user requested usrp->set_gpio_attr(gpio_bank, "CTRL", 0, mask); @@ -198,7 +199,7 @@ void run_bitbang_test(uhd::usrp::multi_usrp::sptr usrp, std::cout << std::endl; std::signal(SIGINT, &sig_int_handler); - while (not stop_signal_called) { + do { // dwell and continuously read back GPIO values auto stop_time = std::chrono::steady_clock::now() + dwell_time; while (not stop_signal_called and std::chrono::steady_clock::now() < stop_time) { @@ -208,7 +209,7 @@ void run_bitbang_test(uhd::usrp::multi_usrp::sptr usrp, std::this_thread::sleep_for(std::chrono::milliseconds(10)); } std::cout << std::endl; - } + } while (repeat && !stop_signal_called); } @@ -468,7 +469,15 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) // The bitbang test is its own thing if (vm.count("bitbang")) { - run_bitbang_test(usrp, gpio_bank, port, ddr, out, mask, num_bits, dwell_time); + run_bitbang_test(usrp, + gpio_bank, + port, + ddr, + out, + mask, + num_bits, + dwell_time, + bool(vm.count("repeat"))); return EXIT_SUCCESS; } -- cgit v1.2.3