summaryrefslogtreecommitdiff
path: root/Radio/HW/BladeRF/common/include
diff options
context:
space:
mode:
Diffstat (limited to 'Radio/HW/BladeRF/common/include')
-rw-r--r--Radio/HW/BladeRF/common/include/conversions.h409
-rw-r--r--Radio/HW/BladeRF/common/include/dc_calibration.h151
-rw-r--r--Radio/HW/BladeRF/common/include/devcfg.h151
-rw-r--r--Radio/HW/BladeRF/common/include/host_config.h333
-rw-r--r--Radio/HW/BladeRF/common/include/host_config.h.in333
-rw-r--r--Radio/HW/BladeRF/common/include/iterators.h59
-rw-r--r--Radio/HW/BladeRF/common/include/log.h144
-rw-r--r--Radio/HW/BladeRF/common/include/logger_id.h61
-rw-r--r--Radio/HW/BladeRF/common/include/minmax.h65
-rw-r--r--Radio/HW/BladeRF/common/include/osx/clock_gettime.h52
-rw-r--r--Radio/HW/BladeRF/common/include/parse.h112
-rw-r--r--Radio/HW/BladeRF/common/include/range.h54
-rw-r--r--Radio/HW/BladeRF/common/include/rel_assert.h14
-rw-r--r--Radio/HW/BladeRF/common/include/sha256.h61
-rw-r--r--Radio/HW/BladeRF/common/include/str_queue.h93
-rw-r--r--Radio/HW/BladeRF/common/include/thread.h74
16 files changed, 2166 insertions, 0 deletions
diff --git a/Radio/HW/BladeRF/common/include/conversions.h b/Radio/HW/BladeRF/common/include/conversions.h
new file mode 100644
index 0000000..5555a29
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/conversions.h
@@ -0,0 +1,409 @@
+/*
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (C) 2014-2018 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef CONVERSIONS_H_
+#define CONVERSIONS_H_
+
+#include <errno.h>
+#include <libbladeRF.h>
+#include <limits.h>
+#include <math.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "host_config.h"
+#include "rel_assert.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Convert a string to a bladerf_version
+ *
+ * Accepted inputs are in the form: X.Y.Z or X.Y.Z-<extra text>
+ *
+ * @param[in] string Version string to convert
+ * @param[out] version Version structure to populate. For a valid string,
+ * the describe member will point to the provided
+ * string argument. The contents of this structure
+ * are undefined when this function returns -1.
+ *
+ * @return 0 on success, -1 if provided string is invalid
+ */
+int str2version(const char *str, struct bladerf_version *version);
+
+/**
+ * Convert a bladerf_dev_speed to a string suitable for printing
+ *
+ * @note The caller should not attempt to modify or free() the returned string.
+ *
+ * @param speed Device speed
+ * @return Const string describing the provided speed
+ */
+const char *devspeed2str(bladerf_dev_speed speed);
+
+/**
+ * Convert a string to libbladeRF log verbosity level
+ *
+ * @param[in] str Input string
+ * @param[out] ok Value is updated to true if the input string was valid
+ *
+ * @return Log level if ok is true, undefined otherwise
+ */
+bladerf_log_level str2loglevel(const char *str, bool *ok);
+
+/**
+ * Convert a module enumeration to a string
+ *
+ * @note The caller should not attempt to modify or free() the returned string.
+ *
+ * @param module Module to convert to string
+ * @return String representation of module
+ */
+const char *module2str(bladerf_module m);
+
+/**
+ * Convert a string to a module enumeration value.
+ *
+ * This is case-insensitive.
+ *
+ * @param str Module as a string. Should be "rx" or "tx".
+ *
+ * @return BLADERF_MODULE_RX, BLADERF_MODULE_TX, or BLADERF_MODULE_INVALID
+ */
+bladerf_module str2module(const char *str);
+
+/**
+ * Convert a channel index to a string
+ *
+ * @note The caller should not attempt to modify or free() the returned string.
+ *
+ * @param ch Channel
+ * @return String representation of channel
+ */
+const char *channel2str(bladerf_channel ch);
+
+/**
+ * Convert a string to a channel index
+ *
+ * This is case-insensitive.
+ *
+ * @param str Channel as a string.
+ * @return BLADERF_CHANNEL_RX(n) or BLADERF_CHANNEL_TX(n),
+ * or BLADERF_CHANNEL_INVALID if not recognized
+ */
+bladerf_channel str2channel(char const *str);
+
+/**
+ * Convert a direction enumeration to a string
+ *
+ * @note The caller should not attempt to modify or free() the returned string.
+ *
+ * @param dir direction
+ * @return String representation of direction
+ */
+const char *direction2str(bladerf_direction dir);
+
+/**
+ * Convert a channel enumeration to a direction
+ *
+ * @param ch channel
+ * @return Direction of the channel
+ */
+bladerf_direction channel2direction(bladerf_channel ch);
+
+/**
+ * Convert a trigger signal enumeration value to a string
+ *
+ * @param trigger Trigger item
+ *
+ * @return String representation or "Unknown"
+ */
+const char *trigger2str(bladerf_trigger_signal trigger);
+
+/**
+ * Conver a string to a trigger signal enumeration value.
+ *
+ * This is case-insensitive.
+ *
+ * @param str Trigger as a string. Valid values include `Miniexp-1`,
+ * `J51-1`, `J71-4`, or `User-0` through `User-7`.
+ *
+ * @return valid bladerf_trigger_signal value, or BLADERF_TRIGGER_INVALID
+ */
+bladerf_trigger_signal str2trigger(const char *str);
+
+/**
+ * Convert a trigger role enumeration value to a string
+ *
+ * @param role Role value
+ *
+ * @return String representation or "Unknown"
+ */
+const char *triggerrole2str(bladerf_trigger_role role);
+
+/**
+ * Convert a string to a trigger role enumeration value
+ *
+ * @param role Role value
+ *
+ * @return String representation or "Unknown"
+ */
+bladerf_trigger_role str2triggerrole(const char *str);
+
+/**
+ * Convert a string to a loopback mode
+ *
+ * @param[in] str String to convert
+ * @param[out] loopback Corresponding loopback mode. Only valid when
+ * this function returns successfully
+ *
+ * @return 0 on success, -1 on invalid string
+ */
+int str2loopback(const char *str, bladerf_loopback *loopback);
+
+/**
+ * @brief Convert a loopback mode to a string const
+ *
+ * @param[in] loopback The loopback mode
+ *
+ * @return NUL-terminated string
+ */
+char const *loopback2str(bladerf_loopback loopback);
+
+/**
+ * Convert RX LNA gain strings to their associated enum values
+ *
+ * @param[in] str Gain string to convert
+ * @param[out] gain Associated LNA gain string. Set to
+ * BLADERF_LNA_GAIN_UNKNOWN on error.
+ *
+ * @return 0 on success, -1 on invalid string
+ */
+int str2lnagain(const char *str, bladerf_lna_gain *gain);
+
+/**
+ * @brief Convert a tuning mode to a string const
+ *
+ * @param[in] mode The tuning mode
+ *
+ * @return NUL-terminated string
+ */
+char const *tuningmode2str(bladerf_tuning_mode mode);
+
+/**
+ * Get a string description of the specified bladeRF backend
+ *
+ * @param b Backend to get a string for
+ *
+ * @return NUL-terminated string
+ */
+const char *backend_description(bladerf_backend b);
+
+/**
+ * Convert bladeRF SC16Q11 DAC/ADC samples to floats
+ *
+ * Note that the both the input and output buffers contain interleaved, where
+ * 1 sample is associated with two array elements:
+ * [I, Q, I, Q, ... I, Q]
+ *
+ * Therefore, the caller must ensure the output buffer large enough to contain
+ * 2*n floats (or 2*n*sizeof(float) bytes).
+ *
+ * @param[in] in Input buffer containing SC16Q11 samples
+ * @param[out] out Output buffer of float values
+ * @param[in] n Number of samples to convert
+ */
+void sc16q11_to_float(const int16_t *in, float *out, unsigned int n);
+
+/**
+ * Convert float samples to bladeRF SC16Q11 DAC/ADC format
+ *
+ * Note that the both the input and output buffers contain interleaved, where
+ * 1 sample is associated with two array elements:
+ * [I, Q, I, Q, ... I, Q]
+ *
+ * Therefore, the caller must ensure the output buffer large enough to contain
+ * 2*n int16_t's (or 2*n*sizeof(int16_t) bytes).
+ *
+ * @param[in] in Input buffer containing float samples
+ * @param[out] out Output buffer of int16_t values
+ * @param[in] n Number of samples to convert
+ */
+void float_to_sc16q11(const float *in, int16_t *out, unsigned int n);
+
+/**
+ * Convert a string to a bladerf_cal_module value
+ *
+ * @param[in] str String to convert
+ *
+ * @return A bladerf_cal_module value. This will be set to
+ * BLADERF_DC_CAL_INVALID if the provided string is invalid.
+ */
+bladerf_cal_module str_to_bladerf_cal_module(const char *str);
+
+/**
+ * Convert a bladerf_smb_mode enumeration value to a string
+ *
+ * @param[in] mode Mode enum value
+ *
+ * @return String representation of enumeration, or "Unknown" for an
+ * invalid value.
+ */
+const char *smb_mode_to_str(bladerf_smb_mode mode);
+
+/**
+ * Convert a string to bladerf_smb_mode value
+ *
+ * @param[in] str String to convert
+ *
+ * @return A BLADERF_SMB_MODE_* value. BLADERF_SMB_MODE_INVALID will
+ * returned for an invalid string.
+ */
+bladerf_smb_mode str_to_smb_mode(const char *str);
+
+/**
+ * Convert a string to bladerf_tuning_mode value
+ *
+ * @param[in] str String to convert
+ *
+ * @return A BLADERF_TUNING_MODE_* value. BLADERF_TUNING_MODE_INVALID will
+ * returned for an invalid string.
+ */
+bladerf_tuning_mode str_to_tuning_mode(const char *str);
+
+/**
+ * Convert an ASCII char string to an unsigned integer and check its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return An unsigned integer converted from an ASCII string
+ */
+unsigned int str2uint(const char *str,
+ unsigned int min,
+ unsigned int max,
+ bool *ok);
+
+/**
+ * Convert an ASCII char string to an integer and check its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return A signed integer converted from an ASCII string
+ */
+int str2int(const char *str, int min, int max, bool *ok);
+
+/**
+ * Convert an ASCII char string to a 64bit unsigned long long integer and check
+ * its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return An unsigned long long integer converted from an ASCII string
+ */
+uint64_t str2uint64(const char *str, uint64_t min, uint64_t max, bool *ok);
+
+/**
+ * Convert an ASCII char string to a double and check its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return A double converted from an ASCII string
+ */
+double str2double(const char *str, double min, double max, bool *ok);
+struct numeric_suffix {
+ const char *suffix;
+ uint64_t multiplier;
+};
+typedef struct numeric_suffix numeric_suffix;
+
+/**
+ * Convert an ASCII char string that has a suffix multipler to an unsigned
+ * integer and check its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[in] suffixes Array of numeric_suffix
+ * @param[in] num_suff Total number of numeric_suffix in suffixes array
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return An unsigned integer converted from an ASCII string
+ */
+unsigned int str2uint_suffix(const char *str,
+ unsigned int min,
+ unsigned int max,
+ const struct numeric_suffix *suffixes,
+ const size_t num_suff,
+ bool *ok);
+
+/**
+ * Convert an ASCII char string that has a suffix multipler to an unsigned
+ * integer and check its bounds
+ *
+ * @param[in] str String to convert
+ * @param[in] min Value below this is bad
+ * @param[in] max Value above this is bad
+ * @param[in] suffixes Array of numeric_suffix
+ * @param[in] num_suff Total number of numeric_suffix in suffixes array
+ * @param[out] ok True if conversion and bounds check did not fail
+ *
+ * @return An unsigned long long integer converted from an ASCII string
+ */
+uint64_t str2uint64_suffix(const char *str,
+ uint64_t min,
+ uint64_t max,
+ const struct numeric_suffix *suffixes,
+ const size_t num_suff,
+ bool *ok);
+
+/**
+ * Convert a string to a boolean
+ *
+ * @param[in] str String to convert
+ * @param[out] val Boolean value
+ *
+ * @return 0 on success, value from \ref RETCODES list on failure
+ */
+int str2bool(const char *str, bool *val);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/dc_calibration.h b/Radio/HW/BladeRF/common/include/dc_calibration.h
new file mode 100644
index 0000000..7259292
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/dc_calibration.h
@@ -0,0 +1,151 @@
+/**
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2015 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/* This file provides DC calibration routines that utilize libbladeRF */
+
+#ifndef DC_CALIBRATION_H_
+#define DC_CALIBRATION_H_
+
+#include <libbladeRF.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dc_calibration_params {
+ uint64_t frequency;
+ int16_t corr_i;
+ int16_t corr_q;
+ float error_i;
+ float error_q;
+
+ int16_t max_dc_i;
+ int16_t max_dc_q;
+ int16_t mid_dc_i;
+ int16_t mid_dc_q;
+ int16_t min_dc_i;
+ int16_t min_dc_q;
+};
+
+/**
+ * Calibrate the specified LMS6002D module.
+ *
+ * Generally, one should run all of these calibrations prior to executing the RX
+ * and TX auto calibration routines.
+ *
+ * Streams should not be running when attempting to call this function.
+ *
+ * Below are the case-insensitive options for the LMS6002D `module` string:
+ * - LPF Tuning: "lpf_tuning", "lpftuning", "tuning"
+ * - TX LPF: "tx_lpf", "txlpf"
+ * - RX LPF: "rx_lpf", "rxlpf"
+ * - RX VGA2 "rx_vga2", "rxvga2"
+ * - All of the above: "all"
+ *
+ * @param dev bladeRF device handle
+ * @param module LMS6002D module to calibrate. Passing NULL is synonymous
+ * with specifying "ALL".
+ *
+ * @return 0 on success or libbladeRF return value on failure.
+ * BLADERF_ERR_INVAL is returned if `module` is invalid.
+ */
+int dc_calibration_lms6(struct bladerf *dev, const char *module);
+
+/**
+ * Perform DC offset calbration of the RX path. Neither RX or TX should be
+ * used during this procedure, as the TX frequency may be adjusted to ensure
+ * good results are obtained.
+ *
+ * The RX input should be disconected from any input sources or antennas when
+ * performing this calibration.
+ *
+ * @pre dc_calibration_lms6() should have been called for all modules prior to
+ * using this function.
+ *
+ * @param[in] dev bladeRF device handle
+ *
+ * @param[inout] params DC calibration input and output parameters. This
+ * list should be populated to describe the
+ * frequencies over which to calibrate. The
+ * `corr_i` and `corr_q` fields will be filled in
+ * for each entry.
+ *
+ * @param[in] num_params Number of entries in the `params` list.
+ *
+ * @param[in] show_status Print status information to stdout
+ *
+ * @return 0 on success or libbladeRF return value on failure.
+ */
+int dc_calibration_rx(struct bladerf *dev,
+ struct dc_calibration_params *params,
+ size_t num_params, bool show_status);
+
+/**
+ * Perform DC offset calbration of the TX path.
+ *
+ * This requires use of both RX and TX modules in an internal loopback mode;
+ * neither should be in use when this function is called. It should not
+ * be neccessary to disconnect the RX and TX ports, but it is still recommended,
+ * just to err on the side of caution.
+ *
+ * @pre dc_calibration_lms6() should have been called for all modules prior to
+ * using this function.
+ *
+ * @param dev bladeRF device handle
+ *
+ * @return 0 on success or libbladeRF return value on failure.
+ */
+int dc_calibration_tx(struct bladerf *dev,
+ struct dc_calibration_params *params,
+ size_t num_params, bool show_status);
+
+/**
+ * Convenience wrapper around dc_cal_rx() and dc_cal_tx()
+ *
+ * @pre dc_calibration_lms6() should have been called for all modules prior to
+ * using this function.
+ *
+ * @param[in] dev Device handle
+ * @param[in] module BLADERF_MODULE_RX or BLADERF_MODULE_TX
+ * @param[inout] params DC calibration input and output parameters. This
+ * list should be populated to describe the
+ * frequencies over which to calibrate. The
+ * `corr_i` and `corr_q` fields will be filled in
+ * for each entry.
+ *
+ * @param[in] num_params Number of entries in the `params` list.
+ * @param[in] show_status Print status information to stdout
+ *
+ * @return 0 on success or libbladeRF return value on failure.
+ */
+int dc_calibration(struct bladerf *dev, bladerf_module module,
+ struct dc_calibration_params *params,
+ size_t num_params, bool show_status);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/devcfg.h b/Radio/HW/BladeRF/common/include/devcfg.h
new file mode 100644
index 0000000..3ebf837
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/devcfg.h
@@ -0,0 +1,151 @@
+/*
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (C) 2014-2015 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef DEVCFG_H_
+#define DEVCFG_H_
+
+#include <stdint.h>
+#include <libbladeRF.h>
+
+#include "rel_assert.h"
+#include "host_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DEVCFG_OPTIONS_BASE "hd:l:v:s:b:f:"
+
+/**
+ * Device configuration parameters
+ */
+struct devcfg {
+ char *device_specifier;
+
+ unsigned int tx_frequency;
+ unsigned int tx_bandwidth;
+ unsigned int tx_samplerate;
+ int txvga1;
+ int txvga2;
+
+ unsigned int rx_frequency;
+ unsigned int rx_bandwidth;
+ unsigned int rx_samplerate;
+ bladerf_lna_gain lnagain;
+ int rxvga1;
+ int rxvga2;
+
+ bladerf_loopback loopback;
+
+ bladerf_log_level verbosity;
+
+ bool enable_xb200;
+
+ unsigned int samples_per_buffer;
+ unsigned int num_buffers;
+ unsigned int num_transfers;
+ unsigned int stream_timeout_ms;
+ unsigned int sync_timeout_ms;
+};
+
+/**
+ * Initialize the specified device_config structure to default values
+ *
+ * @param c Configuration to initialize
+ */
+void devcfg_init(struct devcfg *c);
+
+/**
+ * Deinitialize any items allocated in the provided device configuration
+ *
+ * @param c Configuration to deinitialize
+ */
+void devcfg_deinit(struct devcfg *c);
+
+/**
+ * Creates an option array with the app-specific options appended to the common
+ * devcfg options. The app_options should be 0-terminated.
+ *
+ * The caller is responsible for freeing the resturned structure.
+ *
+ * @return Heap-allocated array on success, NULL on failure
+ */
+struct option *devcfg_get_long_options(const struct option *app_options);
+
+/**
+ * Handle command line arguments and update the specified device configuration
+ * accordingly.
+ *
+ * @param argc # of arguments in argv
+ * @param argv Array of arguments
+ *
+ * @param option_str Options string to pass to getopt_long(). This should
+ * include DEVCFG_OPTIONS_BASE, with any
+ * application-handled options appended.
+ *
+ * @param long_options List of long options created by caller
+ *
+ * @param c Device configuration to update. It should have
+ * already been initialized via devcfg_init()
+ *
+ * @return 0 on success, -1 on failure, 1 if help is requested
+ */
+int devcfg_handle_args(int argc, char **argv,
+ const char *options, const struct option *long_options,
+ struct devcfg *c);
+
+/**
+ * Wrapper around bladerf_sync_config, using parameters in the specified
+ * devcfg. Optionally, enable the associated module.
+ */
+int devcfg_perform_sync_config(struct bladerf *dev,
+ bladerf_module module,
+ bladerf_format format,
+ const struct devcfg *config,
+ bool enable_module);
+
+
+/**
+ * Apply the provided device_config to the specified device
+ *
+ * @param dev Device to configure
+ * @param c Configuration parameters
+ *
+ * @return 0 on succes, -1 on failure
+ */
+int devcfg_apply(struct bladerf *dev, const struct devcfg *c);
+
+/**
+ * Print help info about arguments handled by devcfg_handle_args()
+ *
+ * @param title Optional title to print before usage information
+ */
+void devcfg_print_common_help(const char *title);
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/host_config.h b/Radio/HW/BladeRF/common/include/host_config.h
new file mode 100644
index 0000000..15dded3
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/host_config.h
@@ -0,0 +1,333 @@
+/**
+ * @file host_config.h.in
+ *
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2013-2018 Nuand LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef HOST_CONFIG_H__
+#define HOST_CONFIG_H__
+
+#define BLADERF_OS_LINUX 0
+#define BLADERF_OS_FREEBSD 0
+#define BLADERF_OS_OSX 1
+#define BLADERF_OS_WINDOWS 0
+#define BLADERF_BIG_ENDIAN 0
+
+#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD)
+# error "Build not configured for any supported operating systems"
+#endif
+
+#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS + BLADERF_OS_FREEBSD)
+#error "Build configured for multiple operating systems"
+#endif
+
+#define HAVE_CLOCK_GETTIME 1
+
+/*******************************************************************************
+ * Endianness conversions
+ *
+ * HOST_TO_LE16 16-bit host endianness to little endian conversion
+ * LE16_TO_HOST 16-bit little endian to host endianness conversion
+ * HOST_TO_BE16 16-bit host endianness to big endian conversion
+ * BE16_TO_HOST 16-bit big endian to host endianness conversion
+ * HOST_TO_LE32 32-bit host endianness to little endian conversion
+ * LE32_TO_HOST 32-bit little endian to host endianness conversion
+ * HOST_TO_BE32 32-bit host endianness to big endian conversion
+ * BE32_TO_HOST 32-bit big endian to host endianness conversion
+ * HOST_TO_BE64 64-bit host endianness to big endian conversion
+ * BE64_TO_HOST 64-bit big endian to host endianness conversion
+ ******************************************************************************/
+
+/*-----------------------
+ * Linux
+ *---------------------*/
+#if BLADERF_OS_LINUX
+#include <endian.h>
+
+#define HOST_TO_LE16(val) htole16(val)
+#define LE16_TO_HOST(val) le16toh(val)
+#define HOST_TO_BE16(val) htobe16(val)
+#define BE16_TO_HOST(val) be16toh(val)
+
+#define HOST_TO_LE32(val) htole32(val)
+#define LE32_TO_HOST(val) le32toh(val)
+#define HOST_TO_BE32(val) htobe32(val)
+#define BE32_TO_HOST(val) be32toh(val)
+
+#define HOST_TO_LE64(val) htole64(val)
+#define LE64_TO_HOST(val) le64toh(val)
+#define HOST_TO_BE64(val) be64toh(val)
+#define BE64_TO_HOST(val) be64toh(val)
+
+/*-----------------------
+ * FREEBSD
+ *---------------------*/
+#elif BLADERF_OS_FREEBSD
+#include <sys/endian.h>
+
+#define HOST_TO_LE16(val) htole16(val)
+#define LE16_TO_HOST(val) le16toh(val)
+#define HOST_TO_BE16(val) htobe16(val)
+#define BE16_TO_HOST(val) be16toh(val)
+
+#define HOST_TO_LE32(val) htole32(val)
+#define LE32_TO_HOST(val) le32toh(val)
+#define HOST_TO_BE32(val) htobe32(val)
+#define BE32_TO_HOST(val) be32toh(val)
+
+#define HOST_TO_LE64(val) htole64(val)
+#define LE64_TO_HOST(val) le64toh(val)
+#define HOST_TO_BE64(val) be64toh(val)
+#define BE64_TO_HOST(val) be64toh(val)
+
+/*-----------------------
+ * Apple OSX
+ *---------------------*/
+#elif BLADERF_OS_OSX
+#include <libkern/OSByteOrder.h>
+
+#define HOST_TO_LE16(val) OSSwapHostToLittleInt16(val)
+#define LE16_TO_HOST(val) OSSwapLittleToHostInt16(val)
+#define HOST_TO_BE16(val) OSSwapHostToBigInt16(val)
+#define BE16_TO_HOST(val) OSSwapBigToHostInt16(val)
+
+#define HOST_TO_LE32(val) OSSwapHostToLittleInt32(val)
+#define LE32_TO_HOST(val) OSSwapLittleToHostInt32(val)
+#define HOST_TO_BE32(val) OSSwapHostToBigInt32(val)
+#define BE32_TO_HOST(val) OSSwapBigToHostInt32(val)
+
+#define HOST_TO_LE64(val) OSSwapHostToLittleInt64(val)
+#define LE64_TO_HOST(val) OSSwapLittleToHostInt64(val)
+#define HOST_TO_BE64(val) OSSwapHostToBigInt64(val)
+#define BE64_TO_HOST(val) OSSwapBigToHostInt64(val)
+
+/*-----------------------
+ * Windows
+ *---------------------*/
+#elif BLADERF_OS_WINDOWS
+#include <intrin.h>
+
+/* We'll assume little endian for Windows platforms:
+ * http://blogs.msdn.com/b/larryosterman/archive/2005/06/07/426334.aspx
+ */
+#define HOST_TO_LE16(val) (val)
+#define LE16_TO_HOST(val) (val)
+#define HOST_TO_BE16(val) _byteswap_ushort(val)
+#define BE16_TO_HOST(val) _byteswap_ushort(val)
+
+#define HOST_TO_LE32(val) (val)
+#define LE32_TO_HOST(val) (val)
+#define HOST_TO_BE32(val) _byteswap_ulong(val)
+#define BE32_TO_HOST(val) _byteswap_ulong(val)
+
+
+#define HOST_TO_LE64(val) (val)
+#define LE64_TO_HOST(val) (val)
+#define HOST_TO_BE64(val) _byteswap_uint64(val)
+#define BE64_TO_HOST(val) _byteswap_uint64(val)
+
+/*-----------------------
+ * Unsupported or bug
+ *---------------------*/
+#else
+#error "Encountered an OS that we do not have endian wrappers for?"
+#endif
+
+/*******************************************************************************
+ * Endianness conversions for constants
+ *
+ * We shouldn't be using the above items for assigning constants because the
+ * implementations may be functions [1].
+ *
+ * [1] https://sourceware.org/bugzilla/show_bug.cgi?id=17679#c7
+ ******************************************************************************/
+
+#define BLADERF_BYTESWAP16(x) ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8))
+
+#define BLADERF_BYTESWAP32(x) ((((x) & 0xff000000) >> 24) | \
+ (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | \
+ (((x) & 0x000000ff) << 24) )
+
+#define BLADERF_BYTESWAP64(x) ((((x) & 0xff00000000000000llu) >> 56) | \
+ (((x) & 0x00ff000000000000llu) >> 40) | \
+ (((x) & 0x0000ff0000000000llu) >> 24) | \
+ (((x) & 0x000000ff00000000llu) >> 8) | \
+ (((x) & 0x00000000ff000000llu) << 8) | \
+ (((x) & 0x0000000000ff0000llu) << 24) | \
+ (((x) & 0x000000000000ff00llu) << 40) | \
+ (((x) & 0x00000000000000ffllu) << 56) | \
+
+#if BLADERF_BIG_ENDIAN
+# define HOST_TO_LE16_CONST(x) (BLADERF_BYTESWAP16(x))
+# define LE16_TO_HOST_CONST(x) (BLADERF_BYTESWAP16(x))
+# define HOST_TO_BE16_CONST(x) (x)
+# define BE16_TO_HOST_CONST(x) (x)
+
+# define HOST_TO_LE32_CONST(x) (BLADERF_BYTESWAP32(x))
+# define LE32_TO_HOST_CONST(x) (BLADERF_BYTESWAP32(x))
+# define HOST_TO_BE32_CONST(x) (x)
+# define BE32_TO_HOST_CONST(x) (x)
+
+# define HOST_TO_LE64_CONST(x) (BLADERF_BYTESWAP64(x))
+# define LE64_TO_HOST_CONST(x) (BLADERF_BYTESWAP64(x))
+# define HOST_TO_BE64_CONST(x) (x)
+# define BE64_TO_HOST_CONST(x) (x)
+#else
+# define HOST_TO_LE16_CONST(x) (x)
+# define LE16_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE16_CONST(x) (BLADERF_BYTESWAP16(x))
+# define BE16_TO_HOST_CONST(x) (BLADERF_BYTESWAP16(x))
+
+# define HOST_TO_LE32_CONST(x) (x)
+# define LE32_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE32_CONST(x) (BLADERF_BYTESWAP32(x))
+# define BE32_TO_HOST_CONST(x) (BLADERF_BYTESWAP32(x))
+
+# define HOST_TO_LE64_CONST(x) (x)
+# define LE64_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE64_CONST(x) (BLADERF_BYTESWAP64(x))
+# define BE64_TO_HOST_CONST(x) (BLADERF_BYTESWAP64(x))
+#endif
+
+/*******************************************************************************
+ * Miscellaneous Linux fixups
+ ******************************************************************************/
+#if BLADERF_OS_LINUX
+
+/* Added here just to keep this out of the other source files. We'll have
+ * a few Windows replacements for unistd.h items. */
+#include <unistd.h>
+#include <pwd.h>
+
+/*******************************************************************************
+ * Miscellaneous FREEBSD fixups
+ ******************************************************************************/
+#elif BLADERF_OS_FREEBSD
+
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/sysctl.h>
+
+/*******************************************************************************
+ * Miscellaneous OSX fixups
+ ******************************************************************************/
+#elif BLADERF_OS_OSX
+
+#include <unistd.h>
+#include <pwd.h>
+
+/*******************************************************************************
+ * Miscellaneous Windows fixups
+ ******************************************************************************/
+#elif BLADERF_OS_WINDOWS
+
+/* Rename a few functions and types */
+#include <windows.h>
+#include <io.h>
+#include <direct.h>
+#define usleep(x) Sleep((x+999)/1000)
+
+/* Changes specific to Microsoft Visual Studio and its C89-compliant ways */
+#if _MSC_VER
+# define strtok_r strtok_s
+# define strtoull _strtoui64
+#if _MSC_VER < 1900
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+#else
+#define STDC99
+#endif
+# define strcasecmp _stricmp
+# define strncasecmp _strnicmp
+# define fileno _fileno
+# define strdup _strdup
+# define access _access
+# define chdir _chdir
+# define getcwd _getcwd
+# define rmdir _rmdir
+# define unlink _unlink
+# define mkdir(n, m) _mkdir(n)
+
+/* ssize_t lives elsewhere */
+# include <BaseTsd.h>
+# define ssize_t SSIZE_T
+
+/* With msvc, inline is only available for C++. Otherwise we need to use __inline:
+ * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx */
+# if !defined(__cplusplus)
+# define inline __inline
+# endif
+
+/* Visual studio 2012 compiler (v17.00.XX) doesn't have round functions */
+# if _MSC_VER <= 1700
+# include <math.h>
+ static inline float roundf(float x)
+ {
+ return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
+ }
+ static inline double round(double x)
+ {
+ return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5);
+ }
+# endif
+
+#endif // _MSC_VER
+
+#endif
+
+/* Windows (msvc) does not support C99 designated initializers.
+ *
+ * Therefore, the following macro should be used. However, note that you'll
+ * need to be sure to keep your elements in order to avoid breaking Windows
+ * portability!
+ *
+ * http://stackoverflow.com/questions/5440611/how-to-rewrite-c-struct-designated-initializers-to-c89-resp-msvc-c-compiler
+ *
+ * Here's a sample regexep you could use in vim to clean these up in your code:
+ * @\(\s\+\)\(\.[a-zA-Z0-9_]\+\)\s*=\s*\([a-zA-Z0-9_]\+\)\(,\)\?@\1FIELD_INIT(\2,\3)\4@gc
+ */
+#if _MSC_VER
+# define FIELD_INIT(field, ...) __VA_ARGS__
+#else
+# define FIELD_INIT(field, ...) field = __VA_ARGS__
+#endif // _MSC_VER
+
+/*******************************************************************************
+ * Miscellaneous utility macros
+ ******************************************************************************/
+#define ARRAY_SIZE(n) (sizeof(n) / sizeof(n[0]))
+
+/**
+ * GCC 7+ warns on implicit fallthroughs in switch statements
+ * (-Wimplicit-fallthrough), which we use in a couple places for simplicity.
+ * The statement attribute syntax used to suppress this warning is not
+ * supported by anything else.
+ */
+#if __GNUC__ >= 7
+#define EXPLICIT_FALLTHROUGH __attribute__((fallthrough))
+#else
+#define EXPLICIT_FALLTHROUGH
+#endif // __GNUC__ >= 7
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/host_config.h.in b/Radio/HW/BladeRF/common/include/host_config.h.in
new file mode 100644
index 0000000..844946d
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/host_config.h.in
@@ -0,0 +1,333 @@
+/**
+ * @file host_config.h.in
+ *
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2013-2018 Nuand LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef HOST_CONFIG_H__
+#define HOST_CONFIG_H__
+
+#cmakedefine01 BLADERF_OS_LINUX
+#cmakedefine01 BLADERF_OS_FREEBSD
+#cmakedefine01 BLADERF_OS_OSX
+#cmakedefine01 BLADERF_OS_WINDOWS
+#cmakedefine01 BLADERF_BIG_ENDIAN
+
+#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD)
+# error "Build not configured for any supported operating systems"
+#endif
+
+#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS + BLADERF_OS_FREEBSD)
+#error "Build configured for multiple operating systems"
+#endif
+
+#cmakedefine01 HAVE_CLOCK_GETTIME
+
+/*******************************************************************************
+ * Endianness conversions
+ *
+ * HOST_TO_LE16 16-bit host endianness to little endian conversion
+ * LE16_TO_HOST 16-bit little endian to host endianness conversion
+ * HOST_TO_BE16 16-bit host endianness to big endian conversion
+ * BE16_TO_HOST 16-bit big endian to host endianness conversion
+ * HOST_TO_LE32 32-bit host endianness to little endian conversion
+ * LE32_TO_HOST 32-bit little endian to host endianness conversion
+ * HOST_TO_BE32 32-bit host endianness to big endian conversion
+ * BE32_TO_HOST 32-bit big endian to host endianness conversion
+ * HOST_TO_BE64 64-bit host endianness to big endian conversion
+ * BE64_TO_HOST 64-bit big endian to host endianness conversion
+ ******************************************************************************/
+
+/*-----------------------
+ * Linux
+ *---------------------*/
+#if BLADERF_OS_LINUX
+#include <endian.h>
+
+#define HOST_TO_LE16(val) htole16(val)
+#define LE16_TO_HOST(val) le16toh(val)
+#define HOST_TO_BE16(val) htobe16(val)
+#define BE16_TO_HOST(val) be16toh(val)
+
+#define HOST_TO_LE32(val) htole32(val)
+#define LE32_TO_HOST(val) le32toh(val)
+#define HOST_TO_BE32(val) htobe32(val)
+#define BE32_TO_HOST(val) be32toh(val)
+
+#define HOST_TO_LE64(val) htole64(val)
+#define LE64_TO_HOST(val) le64toh(val)
+#define HOST_TO_BE64(val) be64toh(val)
+#define BE64_TO_HOST(val) be64toh(val)
+
+/*-----------------------
+ * FREEBSD
+ *---------------------*/
+#elif BLADERF_OS_FREEBSD
+#include <sys/endian.h>
+
+#define HOST_TO_LE16(val) htole16(val)
+#define LE16_TO_HOST(val) le16toh(val)
+#define HOST_TO_BE16(val) htobe16(val)
+#define BE16_TO_HOST(val) be16toh(val)
+
+#define HOST_TO_LE32(val) htole32(val)
+#define LE32_TO_HOST(val) le32toh(val)
+#define HOST_TO_BE32(val) htobe32(val)
+#define BE32_TO_HOST(val) be32toh(val)
+
+#define HOST_TO_LE64(val) htole64(val)
+#define LE64_TO_HOST(val) le64toh(val)
+#define HOST_TO_BE64(val) be64toh(val)
+#define BE64_TO_HOST(val) be64toh(val)
+
+/*-----------------------
+ * Apple OSX
+ *---------------------*/
+#elif BLADERF_OS_OSX
+#include <libkern/OSByteOrder.h>
+
+#define HOST_TO_LE16(val) OSSwapHostToLittleInt16(val)
+#define LE16_TO_HOST(val) OSSwapLittleToHostInt16(val)
+#define HOST_TO_BE16(val) OSSwapHostToBigInt16(val)
+#define BE16_TO_HOST(val) OSSwapBigToHostInt16(val)
+
+#define HOST_TO_LE32(val) OSSwapHostToLittleInt32(val)
+#define LE32_TO_HOST(val) OSSwapLittleToHostInt32(val)
+#define HOST_TO_BE32(val) OSSwapHostToBigInt32(val)
+#define BE32_TO_HOST(val) OSSwapBigToHostInt32(val)
+
+#define HOST_TO_LE64(val) OSSwapHostToLittleInt64(val)
+#define LE64_TO_HOST(val) OSSwapLittleToHostInt64(val)
+#define HOST_TO_BE64(val) OSSwapHostToBigInt64(val)
+#define BE64_TO_HOST(val) OSSwapBigToHostInt64(val)
+
+/*-----------------------
+ * Windows
+ *---------------------*/
+#elif BLADERF_OS_WINDOWS
+#include <intrin.h>
+
+/* We'll assume little endian for Windows platforms:
+ * http://blogs.msdn.com/b/larryosterman/archive/2005/06/07/426334.aspx
+ */
+#define HOST_TO_LE16(val) (val)
+#define LE16_TO_HOST(val) (val)
+#define HOST_TO_BE16(val) _byteswap_ushort(val)
+#define BE16_TO_HOST(val) _byteswap_ushort(val)
+
+#define HOST_TO_LE32(val) (val)
+#define LE32_TO_HOST(val) (val)
+#define HOST_TO_BE32(val) _byteswap_ulong(val)
+#define BE32_TO_HOST(val) _byteswap_ulong(val)
+
+
+#define HOST_TO_LE64(val) (val)
+#define LE64_TO_HOST(val) (val)
+#define HOST_TO_BE64(val) _byteswap_uint64(val)
+#define BE64_TO_HOST(val) _byteswap_uint64(val)
+
+/*-----------------------
+ * Unsupported or bug
+ *---------------------*/
+#else
+#error "Encountered an OS that we do not have endian wrappers for?"
+#endif
+
+/*******************************************************************************
+ * Endianness conversions for constants
+ *
+ * We shouldn't be using the above items for assigning constants because the
+ * implementations may be functions [1].
+ *
+ * [1] https://sourceware.org/bugzilla/show_bug.cgi?id=17679#c7
+ ******************************************************************************/
+
+#define BLADERF_BYTESWAP16(x) ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8))
+
+#define BLADERF_BYTESWAP32(x) ((((x) & 0xff000000) >> 24) | \
+ (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | \
+ (((x) & 0x000000ff) << 24) )
+
+#define BLADERF_BYTESWAP64(x) ((((x) & 0xff00000000000000llu) >> 56) | \
+ (((x) & 0x00ff000000000000llu) >> 40) | \
+ (((x) & 0x0000ff0000000000llu) >> 24) | \
+ (((x) & 0x000000ff00000000llu) >> 8) | \
+ (((x) & 0x00000000ff000000llu) << 8) | \
+ (((x) & 0x0000000000ff0000llu) << 24) | \
+ (((x) & 0x000000000000ff00llu) << 40) | \
+ (((x) & 0x00000000000000ffllu) << 56) | \
+
+#if BLADERF_BIG_ENDIAN
+# define HOST_TO_LE16_CONST(x) (BLADERF_BYTESWAP16(x))
+# define LE16_TO_HOST_CONST(x) (BLADERF_BYTESWAP16(x))
+# define HOST_TO_BE16_CONST(x) (x)
+# define BE16_TO_HOST_CONST(x) (x)
+
+# define HOST_TO_LE32_CONST(x) (BLADERF_BYTESWAP32(x))
+# define LE32_TO_HOST_CONST(x) (BLADERF_BYTESWAP32(x))
+# define HOST_TO_BE32_CONST(x) (x)
+# define BE32_TO_HOST_CONST(x) (x)
+
+# define HOST_TO_LE64_CONST(x) (BLADERF_BYTESWAP64(x))
+# define LE64_TO_HOST_CONST(x) (BLADERF_BYTESWAP64(x))
+# define HOST_TO_BE64_CONST(x) (x)
+# define BE64_TO_HOST_CONST(x) (x)
+#else
+# define HOST_TO_LE16_CONST(x) (x)
+# define LE16_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE16_CONST(x) (BLADERF_BYTESWAP16(x))
+# define BE16_TO_HOST_CONST(x) (BLADERF_BYTESWAP16(x))
+
+# define HOST_TO_LE32_CONST(x) (x)
+# define LE32_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE32_CONST(x) (BLADERF_BYTESWAP32(x))
+# define BE32_TO_HOST_CONST(x) (BLADERF_BYTESWAP32(x))
+
+# define HOST_TO_LE64_CONST(x) (x)
+# define LE64_TO_HOST_CONST(x) (x)
+# define HOST_TO_BE64_CONST(x) (BLADERF_BYTESWAP64(x))
+# define BE64_TO_HOST_CONST(x) (BLADERF_BYTESWAP64(x))
+#endif
+
+/*******************************************************************************
+ * Miscellaneous Linux fixups
+ ******************************************************************************/
+#if BLADERF_OS_LINUX
+
+/* Added here just to keep this out of the other source files. We'll have
+ * a few Windows replacements for unistd.h items. */
+#include <unistd.h>
+#include <pwd.h>
+
+/*******************************************************************************
+ * Miscellaneous FREEBSD fixups
+ ******************************************************************************/
+#elif BLADERF_OS_FREEBSD
+
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/sysctl.h>
+
+/*******************************************************************************
+ * Miscellaneous OSX fixups
+ ******************************************************************************/
+#elif BLADERF_OS_OSX
+
+#include <unistd.h>
+#include <pwd.h>
+
+/*******************************************************************************
+ * Miscellaneous Windows fixups
+ ******************************************************************************/
+#elif BLADERF_OS_WINDOWS
+
+/* Rename a few functions and types */
+#include <windows.h>
+#include <io.h>
+#include <direct.h>
+#define usleep(x) Sleep((x+999)/1000)
+
+/* Changes specific to Microsoft Visual Studio and its C89-compliant ways */
+#if _MSC_VER
+# define strtok_r strtok_s
+# define strtoull _strtoui64
+#if _MSC_VER < 1900
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+#else
+#define STDC99
+#endif
+# define strcasecmp _stricmp
+# define strncasecmp _strnicmp
+# define fileno _fileno
+# define strdup _strdup
+# define access _access
+# define chdir _chdir
+# define getcwd _getcwd
+# define rmdir _rmdir
+# define unlink _unlink
+# define mkdir(n, m) _mkdir(n)
+
+/* ssize_t lives elsewhere */
+# include <BaseTsd.h>
+# define ssize_t SSIZE_T
+
+/* With msvc, inline is only available for C++. Otherwise we need to use __inline:
+ * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx */
+# if !defined(__cplusplus)
+# define inline __inline
+# endif
+
+/* Visual studio 2012 compiler (v17.00.XX) doesn't have round functions */
+# if _MSC_VER <= 1700
+# include <math.h>
+ static inline float roundf(float x)
+ {
+ return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
+ }
+ static inline double round(double x)
+ {
+ return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5);
+ }
+# endif
+
+#endif // _MSC_VER
+
+#endif
+
+/* Windows (msvc) does not support C99 designated initializers.
+ *
+ * Therefore, the following macro should be used. However, note that you'll
+ * need to be sure to keep your elements in order to avoid breaking Windows
+ * portability!
+ *
+ * http://stackoverflow.com/questions/5440611/how-to-rewrite-c-struct-designated-initializers-to-c89-resp-msvc-c-compiler
+ *
+ * Here's a sample regexep you could use in vim to clean these up in your code:
+ * @\(\s\+\)\(\.[a-zA-Z0-9_]\+\)\s*=\s*\([a-zA-Z0-9_]\+\)\(,\)\?@\1FIELD_INIT(\2,\3)\4@gc
+ */
+#if _MSC_VER
+# define FIELD_INIT(field, ...) __VA_ARGS__
+#else
+# define FIELD_INIT(field, ...) field = __VA_ARGS__
+#endif // _MSC_VER
+
+/*******************************************************************************
+ * Miscellaneous utility macros
+ ******************************************************************************/
+#define ARRAY_SIZE(n) (sizeof(n) / sizeof(n[0]))
+
+/**
+ * GCC 7+ warns on implicit fallthroughs in switch statements
+ * (-Wimplicit-fallthrough), which we use in a couple places for simplicity.
+ * The statement attribute syntax used to suppress this warning is not
+ * supported by anything else.
+ */
+#if __GNUC__ >= 7
+#define EXPLICIT_FALLTHROUGH __attribute__((fallthrough))
+#else
+#define EXPLICIT_FALLTHROUGH
+#endif // __GNUC__ >= 7
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/iterators.h b/Radio/HW/BladeRF/common/include/iterators.h
new file mode 100644
index 0000000..65127a4
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/iterators.h
@@ -0,0 +1,59 @@
+/**
+ * @file iterators.h
+ *
+ * @brief Useful iterators for working with channels, etc
+ *
+ * Copyright (c) 2018 Nuand LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @brief Translate a bladerf_direction and channel number to a
+ * bladerf_channel
+ *
+ * @param _dir Direction
+ * @param _idx Channel number
+ *
+ * @return BLADERF_CHANNEL_TX(_idx) or BLADERF_CHANNEL_RX(_idx)
+ */
+#define CHANNEL_IDX(_dir, _idx) \
+ (BLADERF_TX == _dir) ? BLADERF_CHANNEL_TX(_idx) : BLADERF_CHANNEL_RX(_idx)
+
+/**
+ * @brief Iterate over all bladerf_directions
+ *
+ * @param _dir Direction
+ */
+#define FOR_EACH_DIRECTION(_dir) \
+ for (_dir = BLADERF_RX; _dir <= BLADERF_TX; ++_dir)
+
+/**
+ * @brief Iterate over all channels in a given direction
+ *
+ * @param _dir Direction
+ * @param _count Number of channels
+ * @param[out] _index Index variable (size_t)
+ * @param[out] _channel Channel variable (bladerf_channel)
+ *
+ * @return { description_of_the_return_value }
+ */
+#define FOR_EACH_CHANNEL(_dir, _count, _index, _channel) \
+ for (_index = 0, _channel = CHANNEL_IDX(_dir, _index); _index < _count; \
+ ++_index, _channel = CHANNEL_IDX(_dir, _index))
diff --git a/Radio/HW/BladeRF/common/include/log.h b/Radio/HW/BladeRF/common/include/log.h
new file mode 100644
index 0000000..0b635b5
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/log.h
@@ -0,0 +1,144 @@
+/**
+ * @file log.h
+ *
+ * @brief Simple log message
+ *
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2013 Nuand LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef LOG_H__
+#define LOG_H__
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "libbladeRF.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef SHORT_FILE_
+# define THIS_FILE SHORT_FILE_
+#else
+#if 0
+# warning "SHORT_FILE_ was not defined. Using __FILE__ instead."
+#endif
+# define THIS_FILE __FILE__
+#endif
+
+#define LOG_STRINGIFY__(x) #x
+#define LOG_STRINGIFY_(x) LOG_STRINGIFY__(x)
+
+#define LOG_EXPAND__(x) #x
+#define LOG_EXPAND_(x) LOG_EXPAND__(x)
+
+/**
+ * @defgroup LOG_MACROS Logging macros
+ * @{
+ */
+
+/** Logs a verbose message. Does not include function/line information */
+#define log_verbose(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_VERBOSE, "[VERBOSE", __VA_ARGS__)
+
+/** Logs a debug message. Does not include function/line information */
+#define log_debug(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_DEBUG, "[DEBUG", __VA_ARGS__)
+
+/** Logs an info message. Does not include function/line information*/
+#define log_info(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_INFO, "[INFO", __VA_ARGS__)
+
+/** Logs a warning message. Includes function/line information */
+#define log_warning(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_WARNING, "[WARNING", __VA_ARGS__)
+
+/** Logs an error message. Includes function/line information */
+#define log_error(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_ERROR, "[ERROR", __VA_ARGS__)
+
+/** Logs a critical error message. Includes function/line information */
+#define log_critical(...) \
+ LOG_WRITE(BLADERF_LOG_LEVEL_CRITICAL, "[CRITICAL", __VA_ARGS__)
+
+/** @} */
+
+#ifdef LOG_INCLUDE_FILE_INFO
+# define LOG_WRITE(LEVEL, LEVEL_STRING, ...) \
+ do { log_write(LEVEL, LEVEL_STRING \
+ " @ " LOG_EXPAND_(THIS_FILE) \
+ ":" LOG_STRINGIFY_(__LINE__) "] " \
+ __VA_ARGS__); \
+ } while (0)
+#else
+# define LOG_WRITE(LEVEL, LEVEL_STRING, ...) \
+ do { log_write(LEVEL, LEVEL_STRING "] " __VA_ARGS__); } while (0)
+#endif
+
+/**
+ * Writes a message to the logger with the specified log level. This function
+ * should only be invoked indirectly through one of the log_*
+ * convenience macros above to ensure consistent formatting of log messages.
+ *
+ * @param level The severity level of the message
+ * @param format The printf-style format string
+ * @param ... Optional values for format specifier substitution
+ */
+#ifdef LOGGING_ENABLED
+void log_write(bladerf_log_level level, const char *format, ...);
+#else
+#define log_write(level, format, ...) do {} while(0)
+#endif
+
+
+/**
+ * Sets the filter level for displayed log messages. Messages that are at
+ * or above the specified log level will be written to the log output, while
+ * messages with a lower log level will be suppressed. This function returns
+ * the previous log level.
+ *
+ * @param level The new log level filter value
+ */
+#ifdef LOGGING_ENABLED
+void log_set_verbosity(bladerf_log_level level);
+#else
+#define log_set_verbosity(level) do {} while (0)
+#endif
+
+/**
+ * @brief Gets the current filter level for displayed log messages.
+ *
+ * @return bladerf_log_level
+ */
+#ifdef LOGGING_ENABLED
+bladerf_log_level log_get_verbosity();
+#else
+#define log_get_verbosity(...) BLADERF_LOG_LEVEL_SILENT
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/logger_id.h b/Radio/HW/BladeRF/common/include/logger_id.h
new file mode 100644
index 0000000..f37da81
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/logger_id.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef LOGGER_ID_H_
+#define LOGGER_ID_H_
+
+#define LOGGER_ID_NONE 0
+#define LOGGER_ID_BLADERF_C 1
+#define LOGGER_ID_FLASH_C 2
+#define LOGGER_ID_FPGA_C 3
+#define LOGGER_ID_GPIF_C 4
+#define LOGGER_ID_LOGGER_C 5
+#define LOGGER_ID_RF_C 6
+#define LOGGER_ID_SPI_FLASH_LIB_C 7
+
+#ifdef LOGGER_ID_STRING
+static inline const char * logger_id_string(uint8_t file_id)
+{
+ switch (file_id) {
+ case LOGGER_ID_NONE:
+ return "<None>";
+ case LOGGER_ID_BLADERF_C:
+ return "bladeRF.c";
+ case LOGGER_ID_FLASH_C:
+ return "flash.c";
+ case LOGGER_ID_FPGA_C:
+ return "fpga.c";
+ case LOGGER_ID_GPIF_C:
+ return "gpif.c";
+ case LOGGER_ID_LOGGER_C:
+ return "logger.c";
+ case LOGGER_ID_RF_C:
+ return "rf.c";
+ case LOGGER_ID_SPI_FLASH_LIB_C:
+ return "spi_flash_lib.c";
+ default:
+ return "<Unknown>";
+ }
+}
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/minmax.h b/Radio/HW/BladeRF/common/include/minmax.h
new file mode 100644
index 0000000..9195250
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/minmax.h
@@ -0,0 +1,65 @@
+/**
+ * @file minmax.h
+ *
+ * @brief These static inline routines are preferred over the use of macros,
+ * as they provide type safety.
+ */
+
+#ifndef MINMAX_H__
+#define MINMAX_H__
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "host_config.h"
+
+static inline size_t min_sz(size_t x, size_t y)
+{
+ return x < y ? x : y;
+}
+
+static inline size_t max_sz(size_t x, size_t y)
+{
+ return x > y ? x : y;
+}
+
+static inline unsigned int uint_min(unsigned int x, unsigned int y)
+{
+ return x < y ? x : y;
+}
+
+static inline unsigned int uint_max(unsigned int x, unsigned int y)
+{
+ return x > y ? x : y;
+}
+
+static inline uint32_t u32_min(uint32_t x, uint32_t y)
+{
+ return x < y ? x : y;
+}
+
+static inline uint32_t u32_max(uint32_t x, uint32_t y)
+{
+ return x > y ? x : y;
+}
+
+static inline int64_t i64_min(int64_t x, int64_t y)
+{
+ return x < y ? x : y;
+}
+
+static inline uint64_t u64_min(uint64_t x, uint64_t y)
+{
+ return x < y ? x : y;
+}
+
+static inline int64_t i64_max(int64_t x, int64_t y)
+{
+ return x > y ? x : y;
+}
+
+static inline uint64_t u64_max(uint64_t x, uint64_t y)
+{
+ return x > y ? x : y;
+}
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/osx/clock_gettime.h b/Radio/HW/BladeRF/common/include/osx/clock_gettime.h
new file mode 100644
index 0000000..f2ee0ce
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/osx/clock_gettime.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2013-2017 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef OSX_CLOCK_GETTIME_H_
+#define OSX_CLOCK_GETTIME_H_
+
+#include "host_config.h"
+#include <time.h>
+
+#if HAVE_CLOCK_GETTIME == 0
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#ifndef __MACH__
+# error "This file is intended for use with OSX systems only."
+#endif // __MACH__
+
+typedef int clockid_t;
+#define CLOCK_REALTIME 0
+
+int clock_gettime(clockid_t clk_id, struct timespec *tp);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif // __cplusplus
+
+#endif // !HAVE_CLOCK_GETTIME
+
+#endif // OSX_CLOCK_GETTIME_H
diff --git a/Radio/HW/BladeRF/common/include/parse.h b/Radio/HW/BladeRF/common/include/parse.h
new file mode 100644
index 0000000..a397e6c
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/parse.h
@@ -0,0 +1,112 @@
+/**
+ * @file parse.h
+ *
+ * @brief String and file parsing functions
+ *
+ * Copyright (c) 2017 Nuand LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef PARSE_H_
+#define PARSE_H_
+
+#include "libbladeRF.h"
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Convert ASCII string into arguments
+ *
+ * @param[in] line Command line string
+ * @param[in] comment_char Everything after this charater is discarded
+ * @param[out] argv A pointer to a double pointer of successfully
+ * extracted arguments
+ *
+ * @return -2 on unterminated quote, -1 on error, otherwise number of arguments
+ */
+int str2args(const char *line, char comment_char, char ***argv);
+
+/**
+ * Free arguments returned by str2args()
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] argv Pointer to table of pointers to arguments
+ */
+void free_args(int argc, char **argv);
+
+struct config_options {
+ char *key;
+ char *value;
+ int lineno;
+};
+
+/**
+ * Convert a bladeRF options file to an array of strings
+ *
+ * @param[in] dev Pointer to bladerf device
+ * @param[in] buf String buffer containing entire file
+ * @param[in] buf_sz String buffer containing entire file
+ * @param[out] opts A pointer to an array of strings containing options for
+ * this device
+ *
+ * @return number of options on success, BLADERF_ERR_* values on other failures
+ */
+int str2options(struct bladerf *dev,
+ const char *buf,
+ size_t buf_sz,
+ struct config_options **opts);
+
+/**
+ * Free an array of previously returned options
+ *
+ * @param[in] optv Pointer to array of config_options
+ * @param[in] optc Number of config_options
+ */
+void free_opts(struct config_options *optv, int optc);
+
+/**
+ * Convert comma-delimited string into integer arguments
+ *
+ * @param[in] line Line to split
+ * @param[out] args Pointer to double-pointer of successfully extracted
+ * integers
+ *
+ * @see free_csv2int()
+ *
+ * @return -1 on error, otherwise number of arguments
+ */
+int csv2int(const char *line, int ***args);
+
+/**
+ * Free array of previously-returned csv2int arguments
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] args Pointer to array of pointers to ints
+ */
+void free_csv2int(int argc, int **args);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/range.h b/Radio/HW/BladeRF/common/include/range.h
new file mode 100644
index 0000000..c15a005
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/range.h
@@ -0,0 +1,54 @@
+/* This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2018 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef RANGE_H_
+#define RANGE_H_
+
+#if !defined(BLADERF_NIOS_BUILD) && !defined(BLADERF_NIOS_PC_SIMULATION)
+#include <libbladeRF.h>
+#else
+#include "libbladeRF_nios_compat.h"
+#endif
+
+#include "bladerf2_common.h"
+
+#ifdef BLADERF_NIOS_BUILD
+// don't do scaling on the Nios, since multiplication and division suck
+#define __scale(r, v) (v)
+#define __unscale(r, v) (v)
+#else
+#define __scale(r, v) ((float)(v) / (r)->scale)
+#define __unscale(r, v) ((float)(v) * (r)->scale)
+#endif // BLADERF_NIOS_BUILD
+
+#define __scale_int(r, v) (__round_int(__scale(r, v)))
+#define __scale_int64(r, v) (__round_int64(__scale(r, v)))
+
+#define __unscale_int(r, v) (__round_int(__unscale(r, v)))
+#define __unscale_int64(r, v) (__round_int64(__unscale(r, v)))
+
+bool is_within_range(struct bladerf_range const *range, int64_t value);
+int64_t clamp_to_range(struct bladerf_range const *range, int64_t value);
+
+#endif // RANGE_H_
diff --git a/Radio/HW/BladeRF/common/include/rel_assert.h b/Radio/HW/BladeRF/common/include/rel_assert.h
new file mode 100644
index 0000000..4727710
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/rel_assert.h
@@ -0,0 +1,14 @@
+#ifndef _REL_ASSERT_H_
+#define _REL_ASSERT_H_
+
+#ifdef NDEBUG
+#define NDEBUG_UNDEF
+#endif
+#undef NDEBUG
+#include <assert.h>
+#ifdef NDEBUG_UNDEF
+#define NDEBUG
+#undef NDEBUG_UNDEF
+#endif
+
+#endif /* _REL_ASSERT_H_ */ \ No newline at end of file
diff --git a/Radio/HW/BladeRF/common/include/sha256.h b/Radio/HW/BladeRF/common/include/sha256.h
new file mode 100644
index 0000000..7517ecd
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/sha256.h
@@ -0,0 +1,61 @@
+/*-
+ * Copyright 2005 Colin Percival
+ * Copyright 2013 Daniel Gröber
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SHA256_H_
+#define _SHA256_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SHA256_DIGEST_SIZE 32
+
+typedef struct SHA256Context {
+ uint32_t state[8];
+ uint32_t count[2];
+ unsigned char buf[64];
+} SHA256_CTX;
+
+void SHA256_Init(SHA256_CTX *);
+void SHA256_Update(SHA256_CTX *, const void *, size_t);
+void SHA256_Final(unsigned char [32], SHA256_CTX *);
+/* char *SHA256_End(SHA256_CTX *, char *); */
+/* char *SHA256_File(const char *, char *); */
+/* char *SHA256_FileChunk(const char *, char *, off_t, off_t); */
+/* char *SHA256_Data(const void *, unsigned int, char *); */
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* !_SHA256_H_ */
diff --git a/Radio/HW/BladeRF/common/include/str_queue.h b/Radio/HW/BladeRF/common/include/str_queue.h
new file mode 100644
index 0000000..9ed1769
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/str_queue.h
@@ -0,0 +1,93 @@
+/**
+ * @file str_queue.h
+ *
+ * @brief Simple string queue
+ *
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2014 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef STR_QUEUE_H_
+#define STR_QUEUE_H_
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct str_queue_entry;
+
+struct str_queue {
+ struct str_queue_entry *head;
+ struct str_queue_entry *tail;
+};
+
+/**
+ * Allocate and initialize a string queue
+ *
+ * @param[in] q Queue to initialize
+ */
+void str_queue_init(struct str_queue *q);
+
+/**
+ * Deallocate all resources used by the specified string queue
+ *
+ * @param[in] q Queue to deinitialize
+ */
+void str_queue_deinit(struct str_queue *q);
+
+/** Deinitialization simply clears out the queue - same operation */
+#define str_queue_clear str_queue_deinit
+
+/**
+ * Add a string to the end of the provided string queue
+ *
+ * @param q String queue to append to
+ * @param cmd_str String to append. This string will be copied
+ * to a heap-allocated buffer.
+ *
+ * @return 0 on success, -1 on memory allocation failure
+ */
+int str_queue_enq(struct str_queue *q, const char *str);
+
+/**
+ * Remove a string from the front of the specified string queue.
+ *
+ * @param[in] q Queue to remove from
+ *
+ * @return Heap-allocated string removed from queue, or NULL if the queue is
+ * empty. The caller is responsible for free()-ing the returned string.
+ */
+char * str_queue_deq(struct str_queue *q);
+
+/**
+ * @return true if the queue is empty
+ */
+bool str_queue_empty(struct str_queue *q);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+
+#endif
diff --git a/Radio/HW/BladeRF/common/include/thread.h b/Radio/HW/BladeRF/common/include/thread.h
new file mode 100644
index 0000000..855a24b
--- /dev/null
+++ b/Radio/HW/BladeRF/common/include/thread.h
@@ -0,0 +1,74 @@
+/**
+ * @file thread.h
+ *
+ * @brief Threading portability and debug wrappers
+ *
+ * This file is part of the bladeRF project:
+ * http://www.github.com/nuand/bladeRF
+ *
+ * Copyright (c) 2014 Nuand LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef BLADERF_THREAD_H_
+#define BLADERF_THREAD_H_
+
+/* Currently, only pthreads is supported. In the future, native windows threads
+ * may be used; one of the objectives of this file is to ease that transistion.
+ */
+#include <pthread.h>
+#include "rel_assert.h"
+
+#define MUTEX pthread_mutex_t
+
+#ifdef ENABLE_LOCK_CHECKS
+# define MUTEX_INIT(m) do { \
+ int status; \
+ pthread_mutexattr_t mutex_attr; \
+ status = pthread_mutexattr_init(&mutex_attr); \
+ assert(status == 0 && "Mutex attr init failure"); \
+ status = pthread_mutexattr_settype(&mutex_attr, \
+ PTHREAD_MUTEX_ERRORCHECK); \
+ assert(status == 0 && "Mutex attr setype failure"); \
+ status = pthread_mutex_init(m, &mutex_attr); \
+ assert(status == 0 && "Mutex init failure"); \
+ } while (0)
+
+# define MUTEX_LOCK(m) do { \
+ int status = pthread_mutex_lock(m); \
+ assert(status == 0 && "Mutex lock failure");\
+ } while (0)
+
+# define MUTEX_UNLOCK(m) do { \
+ int status = pthread_mutex_unlock(m); \
+ assert(status == 0 && "Mutex unlock failure");\
+ } while (0)
+
+# define MUTEX_DESTROY(m) do { \
+ int status = pthread_mutex_destroy(m); \
+ assert(status == 0 && "Mutex destroy failure");\
+ } while (0)
+#else
+# define MUTEX_INIT(m) pthread_mutex_init(m, NULL)
+# define MUTEX_LOCK(m) pthread_mutex_lock(m)
+# define MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
+# define MUTEX_DESTROY(m) pthread_mutex_destroy(m)
+#endif
+
+#endif