aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils/compat_check.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-01-22 09:47:21 -0800
committerMartin Braun <martin.braun@ettus.com>2018-02-19 14:51:47 -0800
commiteff796f64b1e05036b7eca2185f53528a0de870b (patch)
treea470a6d1f3f3d2bb8a422b8b7f3815f2924c766c /host/lib/utils/compat_check.cpp
parent1adae2b432d1b66d7b9133a67fedce8af0b6b560 (diff)
downloaduhd-eff796f64b1e05036b7eca2185f53528a0de870b.tar.gz
uhd-eff796f64b1e05036b7eca2185f53528a0de870b.tar.bz2
uhd-eff796f64b1e05036b7eca2185f53528a0de870b.zip
rfnoc: Factored out FPGA compat check
- Applied changes to DUC and DDC blocks - Fixed minor formatting
Diffstat (limited to 'host/lib/utils/compat_check.cpp')
-rw-r--r--host/lib/utils/compat_check.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/host/lib/utils/compat_check.cpp b/host/lib/utils/compat_check.cpp
new file mode 100644
index 000000000..aebf6e6bf
--- /dev/null
+++ b/host/lib/utils/compat_check.cpp
@@ -0,0 +1,114 @@
+//
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: GPL-3.0
+//
+
+#include <uhd/exception.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhdlib/utils/compat_check.hpp>
+#include <boost/format.hpp>
+
+void uhd::assert_fpga_compat(
+ const size_t uhd_major,
+ const size_t uhd_minor,
+ const uint64_t fpga_compat,
+ const std::string& fpga_component,
+ const std::string& log_component,
+ const bool fail_on_minor_behind
+) {
+ const size_t fpga_major = fpga_compat >> 32;
+ const size_t fpga_minor = fpga_compat & 0xFFFFFFFF;
+
+ if (!log_component.empty()) {
+ UHD_LOGGER_DEBUG(log_component)
+ << "Checking compat number for FPGA component `" << fpga_component
+ << "': Expecting " << uhd_major << "." << uhd_minor << ", actual: "
+ << fpga_major << "." << fpga_minor << "."
+ ;
+ }
+
+ if (uhd_major > fpga_major) {
+ if (!log_component.empty()) {
+ UHD_LOGGER_ERROR(log_component)
+ << "Major compat number mismatch for " << fpga_component << ":"
+ " Expecting " << uhd_major << ", got " << fpga_major << "."
+ ;
+ }
+ throw uhd::runtime_error(str(
+ boost::format("FPGA component `%s' is revision %d and UHD supports"
+ " revision %d. Please either upgrade the FPGA"
+ " image (recommended) or downgrade UHD.")
+ % fpga_component
+ % fpga_major
+ % uhd_major
+ ));
+ }
+ if (uhd_major < fpga_major) {
+ if (!log_component.empty()) {
+ UHD_LOGGER_ERROR(log_component)
+ << "Major compat number mismatch for " << fpga_component << ":"
+ " Expecting " << uhd_major << ", got " << fpga_major << "."
+ ;
+ }
+ throw uhd::runtime_error(str(
+ boost::format("FPGA component `%s' is revision %d and UHD supports"
+ " revision %d. Please either upgrade UHD "
+ " (recommended) or downgrade the FPGA image.")
+ % fpga_component
+ % fpga_major
+ % uhd_major
+ ));
+
+ }
+ if (uhd_minor > fpga_minor) {
+ if (fail_on_minor_behind) {
+ if (!log_component.empty()) {
+ UHD_LOGGER_ERROR(log_component) << str(
+ boost::format("Minor compat number mismatch for `%s':"
+ " Expecting %d.%d, got %d.%d.")
+ % fpga_component
+ % uhd_major
+ % uhd_minor
+ % fpga_major
+ % fpga_minor
+ );
+ }
+ throw uhd::runtime_error(str(
+ boost::format("FPGA component `%s' is revision %d.%d and UHD supports"
+ " revision %d.%d. Please either upgrade UHD "
+ " (recommended) or downgrade the FPGA image.")
+ % fpga_component
+ % fpga_major
+ % fpga_minor
+ % uhd_major
+ % uhd_minor
+ ));
+ } else {
+ if (!log_component.empty()) {
+ UHD_LOGGER_WARNING(log_component) << str(
+ boost::format("Non-critical minor compat number mismatch "
+ "for `%s': Expecting %d.%d, got %d.%d.")
+ % fpga_component
+ % uhd_major
+ % uhd_minor
+ % fpga_major
+ % fpga_minor
+ );
+ }
+ }
+ } else if (uhd_minor < fpga_minor) {
+ if (!log_component.empty()) {
+ UHD_LOGGER_WARNING(log_component) << str(
+ boost::format("Non-critical minor compat number mismatch "
+ "for `%s': Expecting %d.%d, got %d.%d.")
+ % fpga_component
+ % uhd_major
+ % uhd_minor
+ % fpga_major
+ % fpga_minor
+ );
+ }
+ }
+ // We got here? Then all is good.
+}