summaryrefslogtreecommitdiff
path: root/Radio/HW/BladeRF/common/src/range.c
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-11-03 15:56:55 +0000
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-11-03 15:56:55 +0000
commitcf4444e7390365df43ecbd3d130015c1e06ef88f (patch)
tree8a6eb114135a04d5efd5af213577b4fac47532ae /Radio/HW/BladeRF/common/src/range.c
parentca50c0f64f1b2fce46b4cb83ed111854bac13852 (diff)
downloadPrySDR-cf4444e7390365df43ecbd3d130015c1e06ef88f.tar.gz
PrySDR-cf4444e7390365df43ecbd3d130015c1e06ef88f.zip
BladeRF library compiles
Diffstat (limited to 'Radio/HW/BladeRF/common/src/range.c')
-rw-r--r--Radio/HW/BladeRF/common/src/range.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/Radio/HW/BladeRF/common/src/range.c b/Radio/HW/BladeRF/common/src/range.c
new file mode 100644
index 0000000..c16fe22
--- /dev/null
+++ b/Radio/HW/BladeRF/common/src/range.c
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (C) 2018 Nuand LLC
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef BLADERF_NIOS_BUILD
+#include "devices.h"
+#endif // BLADERF_NIOS_BUILD
+
+/* Avoid building this in low-memory situations */
+#if !defined(BLADERF_NIOS_BUILD) || defined(BLADERF_NIOS_LIBAD936X)
+
+#include "range.h"
+
+#if !defined(BLADERF_NIOS_BUILD) && !defined(BLADERF_NIOS_PC_SIMULATION)
+#include "log.h"
+#endif
+
+bool is_within_range(struct bladerf_range const *range, int64_t value)
+{
+ if (NULL == range) {
+ log_error("%s: range is null\n", __FUNCTION__);
+ return false;
+ }
+
+ return (__scale(range, value) >= range->min &&
+ __scale(range, value) <= range->max);
+}
+
+int64_t clamp_to_range(struct bladerf_range const *range, int64_t value)
+{
+ if (NULL == range) {
+ log_error("%s: range is null\n", __FUNCTION__);
+ return value;
+ }
+
+ if (__scale(range, value) < range->min) {
+ log_debug("%s: Requested value %" PRIi64
+ " is below range [%g,%g], clamping to %" PRIi64 "\n",
+ __FUNCTION__, value, __unscale(range, range->min),
+ __unscale(range, range->max),
+ __unscale_int64(range, range->min));
+ value = __unscale_int64(range, range->min);
+ }
+
+ if (__scale(range, value) > range->max) {
+ log_debug("%s: Requested value %" PRIi64
+ " is above range [%g,%g], clamping to %" PRIi64 "\n",
+ __FUNCTION__, value, __unscale(range, range->min),
+ __unscale(range, range->max),
+ __unscale_int64(range, range->max));
+ value = __unscale_int64(range, range->max);
+ }
+
+ return value;
+}
+
+#endif // !defined(BLADERF_NIOS_BUILD) || defined(BLADERF_NIOS_LIBAD936X)