From 30939214df27be85523eeb4d9b6380d55cc3106d Mon Sep 17 00:00:00 2001 From: Joris van Rantwijk Date: Thu, 19 Sep 2024 22:48:46 +0200 Subject: [PATCH] Fix bugs in C++ software --- os/src/userspace/puzzlecmd.cpp | 14 +++++++------- os/src/userspace/puzzlefw.cpp | 3 ++- os/src/userspace/puzzlefw.hpp | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/os/src/userspace/puzzlecmd.cpp b/os/src/userspace/puzzlecmd.cpp index 7aec530..5a61b11 100644 --- a/os/src/userspace/puzzlecmd.cpp +++ b/os/src/userspace/puzzlecmd.cpp @@ -35,14 +35,14 @@ void show_status(puzzlefw::PuzzleFwDevice& device) { printf("Status:\n"); - printf(" timestamp = %llu\n", + printf(" timestamp = %llu\n", (unsigned long long)device.get_timestamp()); for (unsigned int i = 0; i < device.get_analog_channel_count(); i++) { unsigned int sample, min_sample, max_sample; sample = device.get_adc_sample(i); device.get_adc_range(i, min_sample, max_sample); - printf(" channel %u = %5u (min = %u, max = %u)\n", + printf(" channel %u = %5u (min = %u, max = %u)\n", i, sample, min_sample, max_sample); } @@ -56,10 +56,10 @@ void show_status(puzzlefw::PuzzleFwDevice& device) printf(" acquisition = %s\n", device.is_acquisition_enabled() ? "on" : "off"); - printf(" channel mode = %d channels", + printf(" channel mode = %d channels\n", device.is_4channel_mode() ? 4 : 2); - printf(" trigger mode = %s, channel=%u, edge=%s\n", + printf(" trigger mode = %s, ch=%u, edge=%s\n", trigger_mode_to_string(device.get_trigger_mode()).c_str(), device.get_trigger_ext_channel(), device.get_trigger_ext_falling() ? "falling" : "rising"); @@ -71,7 +71,7 @@ void show_status(puzzlefw::PuzzleFwDevice& device) device.get_record_length()); unsigned int divisor = device.get_decimation_factor(); - printf(" rate divisor = %u, sample rate = %u Sa/s\n", + printf(" rate divisor = %u (%u Sa/s)\n", divisor, 125000000 / divisor); printf(" averaging = %s\n", @@ -88,13 +88,13 @@ void show_status(puzzlefw::PuzzleFwDevice& device) if (device.is_digital_simulation_enabled()) { uint32_t simulation_state = device.get_digital_simulation_state(); - printf(" digital simulation = %u %u %u %u\n", + printf(" digital sim = %u %u %u %u\n", simulation_state & 1, (simulation_state >> 1) & 1, (simulation_state >> 2) & 1, (simulation_state >> 3) & 1); } else { - printf(" digital simulation = off\n"); + printf(" digital sim = off\n"); } uint32_t dma_status = device.get_dma_status(); diff --git a/os/src/userspace/puzzlefw.cpp b/os/src/userspace/puzzlefw.cpp index d77750d..ada17e2 100644 --- a/os/src/userspace/puzzlefw.cpp +++ b/os/src/userspace/puzzlefw.cpp @@ -36,7 +36,8 @@ static std::string find_puzzlefw_device_name() // Find entry matching "*.puzzlefw" in /sys filesystem. for (const auto& entry : fs::directory_iterator(SOC_DEVICES_DIR)) { std::string fname = entry.path().filename().string(); - if (fname.compare(fname.size() - 9, 9, ".puzzlefw") == 0) { + if (fname.size() > 9 + && fname.compare(fname.size() - 9, 9, ".puzzlefw") == 0) { return fname; } } diff --git a/os/src/userspace/puzzlefw.hpp b/os/src/userspace/puzzlefw.hpp index 98353d9..755bdad 100644 --- a/os/src/userspace/puzzlefw.hpp +++ b/os/src/userspace/puzzlefw.hpp @@ -202,7 +202,6 @@ public: /** Return the number of analog channels (2 or 4). */ unsigned int get_analog_channel_count() { -// TODO -- modify firmware to add ch4-support bit uint32_t v = read_reg(REG_CH4_MODE); return (v & 0x100) ? 4 : 2; }