From ebfb49095bc9776f0d2028bc13d9c7c4ecfaf0c0 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 6 Jan 2025 13:29:16 -0600 Subject: [PATCH 01/41] hdl: fixed late exit from meta down count state The expected two cycle passing between meta write and idle states is independent of the number of streams. Specifically addresses an off-by-one timestamp error with the bladeRF 1.0. --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index 9ae1d24e..86bf18d3 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -293,7 +293,7 @@ begin meta_future.dma_downcount <= meta_current.dma_downcount - NUM_STREAMS; end if; - if( meta_current.dma_downcount <= NUM_STREAMS ) then + if( meta_current.dma_downcount <= 2 ) then -- Look for 2 because of the 2 cycles passing -- through IDLE and META_WRITE after this. -- 8bit format requires an additional 2 cycle delay. From 6fac4cd67219876b0241a353c6caf39d67cf95e4 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 16 Jan 2025 13:26:01 -0600 Subject: [PATCH 02/41] doc: fix API sections menu item with Doxygen 1.9.8 The API sections aren't stored as modules anymore. They're topics. Error likely introduced at doxygen commit: 6d80fc7e5 --- host/libraries/libbladeRF/doc/doxygen/layout.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/host/libraries/libbladeRF/doc/doxygen/layout.xml b/host/libraries/libbladeRF/doc/doxygen/layout.xml index e468b13a..faee2c71 100644 --- a/host/libraries/libbladeRF/doc/doxygen/layout.xml +++ b/host/libraries/libbladeRF/doc/doxygen/layout.xml @@ -5,6 +5,7 @@ + From 5daf75c84e53351c995701aeb4e052a436028e70 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 16 Jan 2025 14:04:01 -0600 Subject: [PATCH 03/41] doc: added packet length warning for BLADERF_FORMAT_PACKET_META A packet length of (n*256-4) DWORDs will cause the synchronous buffer it's filled into to indefinitely persist. --- host/libraries/libbladeRF/include/libbladeRF.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 5deca906..0e0a922d 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -2217,6 +2217,13 @@ typedef enum { * USB 2.0 Hi-Speed or USB 3.0 SuperSpeed for packets for this streaming * format. * + * @warning A packet length of (n*256-4) DWORDs will cause the synchronous + * buffer it's filled into to indefinitely persist. For instance, if a + * packet containing 252 DWORDs is filled into buffer N, buffer N will + * always return that first 252 dword packet. It is recommended to avoid + * these specific packet lengths (252, 508, 764, 1020, etc. DWORDs) + * until this limitation is resolved. + * * @see STREAMING_FORMAT_METADATA * @see The `src/streaming/metadata.h` header in the libbladeRF codebase. */ From afd2da9cdab42f07f8e9afbeca1ad729d8819241 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 19 Aug 2024 16:23:44 -0500 Subject: [PATCH 04/41] hdl: added git information to build output --- hdl/quartus/build_bladerf.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hdl/quartus/build_bladerf.sh b/hdl/quartus/build_bladerf.sh index 583900a4..a1e9e742 100755 --- a/hdl/quartus/build_bladerf.sh +++ b/hdl/quartus/build_bladerf.sh @@ -462,6 +462,18 @@ if [[ ${flow} == "full" ]]; then sha256sum $RBF > $RBF.sha256sum MD5SUM=$(cat $RBF.md5sum | awk '{ print $1 }') SHA256SUM=$(cat $RBF.sha256sum | awk '{ print $1 }') + + GIT_HASH=$(git rev-parse --short HEAD) + GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + GIT_DIRTY=$(git diff --quiet && echo "clean" || echo "dirty") + + cat << EOF > git_info.txt +Git Information: +Commit Hash: $GIT_HASH +Branch: $GIT_BRANCH +Working Directory: $GIT_DIRTY +EOF + popd echo "" @@ -473,6 +485,10 @@ if [[ ${flow} == "full" ]]; then echo " MD5: $MD5SUM" echo " SHA256: $SHA256SUM" echo "" + echo " Git Information:" + echo " Commit: $GIT_HASH ($GIT_DIRTY)" + echo " Branch: $GIT_BRANCH" + echo "" cat "$BUILD_OUTPUT_DIR/$BUILD_NAME.fit.summary" | sed -e 's/^\(.\)/ \1/g' echo "##########################################################################" fi From efbebc8e88a706cc0a08df8f61823bc2e65b2979 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Fri, 12 Jul 2024 15:32:21 -0500 Subject: [PATCH 05/41] libbladeRF: test: added streaming test The streaming test allows for cross testing between MIMO, SISO, TX, RX, meta, and non-meta configurations. Example: TX a CW at 50MSPS and at a frequency of (915MHz+50MHz/16) with meta enabled ./output/libbladeRF_test_streaming -te -s 50M Example: TX and RX at 25MSPS and at a frequency of (915MHz+25MHz/16) without meta enabled ./output/libbladeRF_test_streaming -tr -s 25M --- host/libraries/libbladeRF_test/CMakeLists.txt | 1 + .../test_streaming/CMakeLists.txt | 17 + .../libbladeRF_test/test_streaming/src/main.c | 329 ++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt create mode 100644 host/libraries/libbladeRF_test/test_streaming/src/main.c diff --git a/host/libraries/libbladeRF_test/CMakeLists.txt b/host/libraries/libbladeRF_test/CMakeLists.txt index 17ecdc09..00fc3efe 100644 --- a/host/libraries/libbladeRF_test/CMakeLists.txt +++ b/host/libraries/libbladeRF_test/CMakeLists.txt @@ -19,6 +19,7 @@ add_subdirectory(test_quick_retune) add_subdirectory(test_repeated_stream) add_subdirectory(test_rx_discont) add_subdirectory(test_scheduled_retune) +add_subdirectory(test_streaming) add_subdirectory(test_sync) add_subdirectory(test_timestamps) add_subdirectory(test_tune_timing) diff --git a/host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt b/host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt new file mode 100644 index 00000000..ffc48c12 --- /dev/null +++ b/host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.5) +project(libbladeRF_test_streaming C) + +set(INCLUDES + ${libbladeRF_SOURCE_DIR}/include) +if(MSVC) + set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES}) +endif() + +set(SRC + ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c + src/main.c) + +include_directories(${INCLUDES} ${CURL_INCLUDE_DIR} include) +add_executable(${PROJECT_NAME} ${SRC}) + +target_link_libraries(${PROJECT_NAME} libbladerf_shared m) diff --git a/host/libraries/libbladeRF_test/test_streaming/src/main.c b/host/libraries/libbladeRF_test/test_streaming/src/main.c new file mode 100644 index 00000000..e92c17f5 --- /dev/null +++ b/host/libraries/libbladeRF_test/test_streaming/src/main.c @@ -0,0 +1,329 @@ +#include +#include +#include +#include +#include +#include +#include "conversions.h" + +#define INT12_MAX 2047 +#define BUFFER_SIZE_ALIGNMENT 1024 + +#define CHECK_STATUS(fn) \ + do { \ + status = (fn); \ + if (status != 0) { \ + fprintf(stderr, "Error at %s:%d (%s): %s\n", \ + __FILE__, __LINE__, __func__, bladerf_strerror(status)); \ + goto error; \ + } \ + } while (0) + +typedef struct { + bool tx; + bool rx; + bool mimo; + size_t num_samples; + uint64_t sample_rate; + int16_t *tx_samples; + int16_t *rx_samples; + bladerf_format format; + struct bladerf_metadata tx_meta; + struct bladerf_metadata rx_meta; + size_t num_buffers; + size_t buffer_size; + size_t num_transfers; + size_t timeout_ms; +} test_config; + +void print_config(const test_config *config, const char *device_string, const char *fpga_file) { + printf("\nConfiguration Summary:\n"); + printf("---------------------\n"); + printf("Device: %s\n", device_string ? device_string : "any"); + printf("FPGA file: %s\n", fpga_file ? fpga_file : "Not specified"); + printf("TX enabled: %s\n", config->tx ? "Yes" : "No"); + printf("RX enabled: %s\n", config->rx ? "Yes" : "No"); + printf("MIMO enabled: %s\n", config->mimo ? "Yes" : "No"); + printf("Format: %s\n", config->format == BLADERF_FORMAT_SC16_Q11_META ? "SC16 Q11 META" : "SC16 Q11"); + printf("Sample rate: %.3f MHz\n", config->sample_rate / 1e6); + printf("# of samples: %zu\n", config->num_samples); + printf("Buffer size: %zu\n", config->buffer_size); + printf("# of buffers: %zu\n", config->num_buffers); + printf("# of transfers: %zu\n", config->num_transfers); + printf("---------------------\n\n"); +} + + +// Define suffix table for engineering notation +static const struct numeric_suffix freq_suffixes[] = { + { "K", 1000 }, + { "k", 1000 }, + { "M", 1000000 }, + { "m", 1000000 }, + { "G", 1000000000 }, + { "g", 1000000000 }, +}; + +void print_bladerf_flag_statuses(uint32_t flags) { + printf("BladeRF Flag Statuses:\n"); + printf("%-40s %d\n", "BLADERF_META_STATUS_OVERRUN:", !!(flags & BLADERF_META_STATUS_OVERRUN)); + printf("%-40s %d\n", "BLADERF_META_STATUS_UNDERRUN:", !!(flags & BLADERF_META_STATUS_UNDERRUN)); + printf("%-40s %d\n", "BLADERF_META_FLAG_TX_BURST_START:", !!(flags & BLADERF_META_FLAG_TX_BURST_START)); + printf("%-40s %d\n", "BLADERF_META_FLAG_TX_BURST_END:", !!(flags & BLADERF_META_FLAG_TX_BURST_END)); + printf("%-40s %d\n", "BLADERF_META_FLAG_TX_NOW:", !!(flags & BLADERF_META_FLAG_TX_NOW)); + printf("%-40s %d\n", "BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP:", !!(flags & BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP)); + printf("%-40s %d\n", "BLADERF_META_FLAG_RX_NOW:", !!(flags & BLADERF_META_FLAG_RX_NOW)); + printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_UNDERFLOW:", !!(flags & BLADERF_META_FLAG_RX_HW_UNDERFLOW)); + printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_MINIEXP1:", !!(flags & BLADERF_META_FLAG_RX_HW_MINIEXP1)); + printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_MINIEXP2:", !!(flags & BLADERF_META_FLAG_RX_HW_MINIEXP2)); +} + +void print_help() { + printf("Usage: test_streaming [options]\n"); + printf("Options:\n"); + printf(" -d, --device Specify the device string\n"); + printf(" -f, --fpga Specify the FPGA file\n"); + printf(" -v, --verbosity Enable verbose logging\n"); + printf(" -t, --tx Enable TX test\n"); + printf(" -r, --rx Enable RX test\n"); + printf(" -m, --mimo Enable MIMO test\n"); + printf(" -e, --meta Enable META test\n"); + printf(" -s, --samplerate Specify the sample rate\n"); + printf(" -n, --num-samples Specify the number of samples\n"); + printf(" -b, --buffer-size Specify the buffer size (multiple of 1024)\n"); + printf(" -h, --help Display this help message\n"); + printf("\n"); + + printf("Description:\n"); + printf("The streaming test allows for cross testing between MIMO, SISO, TX, RX, meta,\n"); + printf("and non-meta configurations.\n"); + printf("\n"); + + printf("Example: TX a CW at 50MSPS and at a frequency of (915MHz+50MHz/16) with meta enabled\n"); + printf("./output/libbladeRF_test_streaming -te -s 50M\n"); + printf("\n"); + printf("Example: TX and RX at 25MSPS and at a frequency of (915MHz+25MHz/16) without meta enabled\n"); + printf("./output/libbladeRF_test_streaming -tr -s 25M\n"); +} + +int main(int argc, char *argv[]) +{ + int status = 0; + struct bladerf *dev = NULL; + const char *fpga_file = NULL; + const char *device_string = NULL; + int c; + bool ok; + + test_config config = { + .tx = false, + .rx = false, + .mimo = false, + .sample_rate = 61.44e6, + .num_samples = 5 * 61.44e6, + .tx_samples = NULL, + .format = BLADERF_FORMAT_SC16_Q11, + .num_buffers = 512, + .buffer_size = 4096, + .num_transfers = 64, + .timeout_ms = 1000, + .tx_meta.flags = BLADERF_META_FLAG_TX_BURST_START | + BLADERF_META_FLAG_TX_NOW | + BLADERF_META_FLAG_TX_BURST_END, + .rx_meta.flags = BLADERF_META_FLAG_RX_NOW, + }; + + bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_INFO); + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"device", required_argument, 0, 'd'}, + {"fpga", required_argument, 0, 'f'}, + {"verbosity", no_argument, 0, 'v'}, + {"tx", no_argument, 0, 't'}, + {"rx", no_argument, 0, 'r'}, + {"mimo", no_argument, 0, 'm'}, + {"meta", no_argument, 0, 'e'}, + {"samplerate", required_argument, 0, 's'}, + {"num-samples", required_argument, 0, 'n'}, + {"buffer-size", required_argument, 0, 'b'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "d:f:vtrmes:n:b:h", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'd': + device_string = optarg; + break; + case 'f': + fpga_file = optarg; + break; + case 'v': + bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE); + break; + case 't': + config.tx = true; + break; + case 'r': + config.rx = true; + break; + case 'm': + config.mimo = true; + break; + case 'n': + config.num_samples = str2uint64_suffix( + optarg, 1, UINT64_MAX, freq_suffixes, + sizeof(freq_suffixes) / sizeof(freq_suffixes[0]), &ok); + if (!ok) { + fprintf(stderr, "Invalid number of samples: %s\n", optarg); + exit(EXIT_FAILURE); + } + break; + case 'b': + size_t requested_size = strtoull(optarg, NULL, 0); + config.buffer_size = ((requested_size + BUFFER_SIZE_ALIGNMENT - 1) / BUFFER_SIZE_ALIGNMENT) * BUFFER_SIZE_ALIGNMENT; + if (requested_size % BUFFER_SIZE_ALIGNMENT != 0) { + fprintf(stderr, "Requested buffer size rounded up to %zu\n", config.buffer_size); + } + break; + case 'e': + config.format = BLADERF_FORMAT_SC16_Q11_META; + break; + case 's': + config.sample_rate = str2uint64_suffix( + optarg, 0, UINT64_MAX, freq_suffixes, + sizeof(freq_suffixes) / sizeof(freq_suffixes[0]), &ok); + if (!ok) { + fprintf(stderr, "Invalid sample rate: %s\n", optarg); + exit(EXIT_FAILURE); + } + break; + case 'h': + case '?': + print_help(); + exit(EXIT_FAILURE); + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + + if (!config.tx && !config.rx) { + fprintf(stderr, "[Error] TX or RX must be specified.\n"); + print_help(); + exit(EXIT_FAILURE); + } + + print_config(&config, device_string, fpga_file); + + // Allocate memory for samples (2* for IQ components and 2* for MIMO) + config.tx_samples = malloc(4 * config.num_samples * sizeof(int16_t)); + config.rx_samples = malloc(4 * config.num_samples * sizeof(int16_t)); + if (config.tx_samples == NULL || config.rx_samples == NULL) { + fprintf(stderr, "Failed to allocate memory for samples\n"); + exit(EXIT_FAILURE); + } + + printf("Opening device: %s\n", (device_string == NULL) ? "any" : device_string); + CHECK_STATUS(bladerf_open(&dev, device_string)); + + if (fpga_file != NULL) { + printf("Loading the FPGA image...\n"); + CHECK_STATUS(bladerf_load_fpga(dev, fpga_file)); + } + + printf("Setting sample rate to %0.3f MHz...\n", config.sample_rate / 1e6); + CHECK_STATUS(bladerf_set_sample_rate(dev, BLADERF_CHANNEL_RX(0), config.sample_rate, NULL)); + CHECK_STATUS(bladerf_set_sample_rate(dev, BLADERF_CHANNEL_TX(0), config.sample_rate, NULL)); + + printf("Setting frequency to 915 MHz...\n"); + CHECK_STATUS(bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(0), 915e6)); + CHECK_STATUS(bladerf_set_frequency(dev, BLADERF_CHANNEL_TX(0), 915e6)); + + CHECK_STATUS(bladerf_set_gain(dev, BLADERF_CHANNEL_TX(0), 30)); + CHECK_STATUS(bladerf_set_gain(dev, BLADERF_CHANNEL_RX(0), 0)); + + for (size_t i = 0; i < config.num_samples; i++) { + double angle = (2.0 * M_PI * (i % 16)) / 16.0; + config.tx_samples[2 * i] = (int16_t)round(INT12_MAX * cos(angle)); // I component + config.tx_samples[2 * i + 1] = (int16_t)round(INT12_MAX * sin(angle)); // Q component + } + + if (config.mimo) { + for (size_t i = 0; i < config.num_samples; i++) { + double angle = (2.0 * M_PI * (i % 16)) / 16.0; + config.tx_samples[4 * i + 0] = (int16_t)round(INT12_MAX * cos(angle)); // Ch0 I + config.tx_samples[4 * i + 1] = (int16_t)round(INT12_MAX * sin(angle)); // Ch0 Q + config.tx_samples[4 * i + 2] = (int16_t)round(INT12_MAX * cos(angle)); // Ch1 I + config.tx_samples[4 * i + 3] = (int16_t)round(INT12_MAX * sin(angle)); // Ch1 Q + } + } + + if (config.tx) { + printf("Streaming TX...\n"); + CHECK_STATUS(bladerf_sync_config( + dev, (config.mimo == true) ? BLADERF_TX_X2 : BLADERF_TX_X1, + config.format, config.num_buffers, config.buffer_size, + config.num_transfers, config.timeout_ms)); + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(0), true)); + if (config.mimo) + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(1), true)); + CHECK_STATUS(bladerf_sync_tx(dev, config.tx_samples, config.num_samples, + &config.tx_meta, 5000)); + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(0), false)); + } + + if (config.rx) { + printf("Streaming RX...\n"); + CHECK_STATUS(bladerf_sync_config( + dev, (config.mimo == true) ? BLADERF_RX_X2 : BLADERF_RX_X1, + config.format, config.num_buffers, config.buffer_size, + config.num_transfers, config.timeout_ms)); + + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), true)); + if (config.mimo) + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(1), true)); + + /* Retrieve the current timestamp */ + config.rx_meta.flags = 0; + status = bladerf_get_timestamp(dev, BLADERF_RX, &config.rx_meta.timestamp); + if (status != 0) { + fprintf(stderr, "Failed to get current RX timestamp: %s\n", + bladerf_strerror(status)); + } else { + printf("Current RX timestamp: 0x%016" PRIx64 "\n", config.rx_meta.timestamp); + } + + /* Schedule first RX to be 0.1s in the future */ + config.rx_meta.timestamp += config.sample_rate / 10; + printf("Scheduling RX for 0x%016" PRIx64 "\n", config.rx_meta.timestamp); + + status = bladerf_sync_rx(dev, config.rx_samples, config.num_samples, + &config.rx_meta, config.timeout_ms); + if (status != 0) { + fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); + } else if (config.rx_meta.status & BLADERF_META_STATUS_OVERRUN) { + fprintf(stderr, "Overrun detected. %u valid samples were read.\n", + config.rx_meta.actual_count); + print_bladerf_flag_statuses(config.rx_meta.status); + } else { + printf("RX'd %u samples at t=0x%016" PRIx64 "\n", config.rx_meta.actual_count, + config.rx_meta.timestamp); + } + CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), false)); + } + +error: + if (config.tx_samples) + free(config.tx_samples); + if (config.rx_samples) + free(config.rx_samples); + if (dev) + bladerf_close(dev); + + return status; +} From ad10742e1e44ee9fa105046e6a1c028b942593d4 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 24 Jul 2024 11:22:53 -0500 Subject: [PATCH 06/41] hdl: test: added gpif fifo stress test testbench This copies the gpif 8b testbench, but with 7 blocks per TX iteration and 2 subsequent iteration repeats. Run for 4ms to find channel shift reset failure. --- .../fx3_gpif_iq_8bit_fifo_stress_tb.do | 12 + .../tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd | 840 ++++++++++++++++++ .../vhdl/tb/fx3_model_fifo_stress.vhd | 279 ++++++ 3 files changed, 1131 insertions(+) create mode 100644 hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_8bit_fifo_stress_tb.do create mode 100644 hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd create mode 100644 hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd diff --git a/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_8bit_fifo_stress_tb.do b/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_8bit_fifo_stress_tb.do new file mode 100644 index 00000000..c96b41fe --- /dev/null +++ b/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_8bit_fifo_stress_tb.do @@ -0,0 +1,12 @@ +source ../../../ip/nuand/nuand.do + +vcom -work nuand -2008 ../vhdl/rx.vhd +vcom -work nuand -2008 ../vhdl/tx.vhd + +vlib rtl_work +vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd + +compile_nuand ../../../ip/nuand bladerf-micro + +vcom -work nuand -2008 ../vhdl/tb/fx3_model_fifo_stress.vhd +vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd new file mode 100644 index 00000000..ce575ef3 --- /dev/null +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd @@ -0,0 +1,840 @@ +-- Copyright (c) 2024 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. + +library ieee; + use ieee.std_logic_1164.all; + use ieee.numeric_std.all; + +library rtl_work; + +library altera_lnsim; + use altera_lnsim.altera_pll; + +library nuand; + use nuand.util.all ; + use nuand.fifo_readwrite_p.all; + use nuand.common_dcfifo_p.all; + use nuand.bladerf_p.all; + +entity fx3_gpif_iq_8bit_fifo_stress is + generic ( + -- For bladeRF2 (2x2 MIMO): + NUM_MIMO_STREAMS : natural := 2; + FIFO_READER_READ_THROTTLE : natural := 0; + + ENABLE_CHANNEL_0 : std_logic := '1'; + ENABLE_CHANNEL_1 : std_logic := '0'; + EIGHT_BIT_MODE_EN : std_logic := '1' + ); +end entity; + +architecture arch of fx3_gpif_iq_8bit_fifo_stress is + + -- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock + constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0); + + -- For reasons unknown, simulation of this system in ModelSim requires that + -- wrreq and data be asserted shortly before the rising clock edge. Sigh... + constant FIFO_WORKAROUND : time := 1 ps; + + type fx3_control_t is record + usb_speed : std_logic; + tx_enable : std_logic; + rx_enable : std_logic; + meta_enable : std_logic; + packet : std_logic; + end record; + + type fx3_gpif_t is record + gpif_in : std_logic_vector(31 downto 0); + gpif_out : std_logic_vector(31 downto 0); + gpif_oe : std_logic; + ctl_in : std_logic_vector(12 downto 0); + ctl_out : std_logic_vector(12 downto 0); + ctl_oe : std_logic_vector(12 downto 0); + end record; + + signal sys_rst : std_logic := '1'; + signal done : boolean := false; + + signal fx3_pclk : std_logic := '1'; + signal fx3_pclk_pll : std_logic := '1'; + signal sys_clk : std_logic := '1'; + + signal pll_reset : std_logic := '0'; + signal pll_locked : std_logic := '0'; + signal fx3_control : fx3_control_t; + signal fx3_gpif : fx3_gpif_t; + signal fx3_gpif_i : std_logic_vector(31 downto 0); + signal fx3_ctl_i : std_logic_vector(12 downto 0); + + -- Control mapping + alias dma0_rx_ack is fx3_ctl_i( 0); + alias dma1_rx_ack is fx3_ctl_i( 1); + alias dma2_tx_ack is fx3_ctl_i( 2); + alias dma3_tx_ack is fx3_ctl_i( 3); + alias dma_rx_enable is fx3_ctl_i( 4); + alias dma_tx_enable is fx3_ctl_i( 5); + alias dma_idle is fx3_ctl_i( 6); + alias system_reset is fx3_ctl_i( 7); + alias dma0_rx_reqx is fx3_ctl_i( 8); + alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk + alias dma2_tx_reqx is fx3_ctl_i(10); + alias dma3_tx_reqx is fx3_ctl_i(11); + + signal loopback_i : signed(15 downto 0) := (others =>'0'); + signal loopback_q : signed(15 downto 0) := (others =>'0'); + signal loopback_valid : std_logic := '0'; + signal loopback_enabled : std_logic := '0'; + + signal tx_clock : std_logic := '1' ; + signal rx_clock : std_logic := '1' ; + + signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT; + signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT; + signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT; + signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT; + signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT; + + signal rx_mux_i : signed(15 downto 0); + signal rx_mux_q : signed(15 downto 0); + signal rx_mux_valid : std_logic; + + signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' ); + signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' ); + + constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ; + constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ; + constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ; + + signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE); + signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE); + signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE); + signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE); + + signal tx_reset : std_logic := '0'; + signal tx_ts_reset : std_logic := '0'; + signal rx_reset : std_logic := '0'; + signal rx_ts_reset : std_logic := '0'; + + signal meta_en_tx : std_logic := '0'; + signal meta_en_rx : std_logic := '0'; + + signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT; + signal tx_packet_control : packet_control_t; + + signal trigger_signal_sync_tb : std_logic; + signal adc_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' ); + + function data_gen (count : natural) return std_logic_vector is + variable msw, lsw : std_logic_vector(15 downto 0); + begin + msw := std_logic_vector(to_signed(count, 16)); + lsw := std_logic_vector(to_signed(-count, 16)); + + return (msw & lsw); + end function data_gen; + + signal rx_packet_ready : std_logic; + +begin + + -- ======================================================================== + -- Brief summary of data flow + -- ======================================================================== + -- + -- Simulated samples flow from fx3_model's TX side to its RX side. The + -- validity of the data is checked there. + -- + -- entity U_fx3_model FX3 model, TX process + -- signal fx3_gpif_i fx3_gpif.gpif_oe is '0' + -- process register_gpif + -- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA) + -- entity U_fx3_gpif GPIF implementation, write side + -- signal tx_sample_fifo.w* TX fifo, write side + -- entity U_tx_sample_fifo + -- signal tx_sample_fifo.r* TX fifo, read side + -- process tx_mux + -- signal loopback_fifo.w* Loopback fifo, write side + -- entity U_rx_loopback_fifo + -- signal loopback_fifo.r* Loopback fifo, read side + -- process loopback_fifo_control + -- signal loopback_{i,q,valid} + -- process rx_mux + -- signal rx_mux_{i,q,valid} + -- entity U_fifo_writer + -- signal rx_sample_fifo.w* RX fifo, write side + -- entity U_rx_sample_fifo + -- signal rx_sample_fifo.r* RX fifo, read side + -- entity U_fx3_gpif GPIF implementation, read side + -- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3) + -- process register_gpif + -- signal fx3_gpif_i fx3_gpif.gpif_oe is '1' + -- entity U_fx3_model FX3 model, RX process + + + -- ======================================================================== + -- Instantiations + -- ======================================================================== + + -- Unit under test + -- Clock domain: fx3_pclk_pll + U_fx3_gpif : entity nuand.fx3_gpif + port map ( + pclk => fx3_pclk_pll, + reset => sys_rst, + usb_speed => fx3_control.usb_speed, + gpif_in => fx3_gpif.gpif_in, + gpif_out => fx3_gpif.gpif_out, + gpif_oe => fx3_gpif.gpif_oe, + ctl_in => fx3_gpif.ctl_in, + ctl_out => fx3_gpif.ctl_out, + ctl_oe => fx3_gpif.ctl_oe, + tx_enable => fx3_control.tx_enable, + rx_enable => fx3_control.rx_enable, + meta_enable => fx3_control.meta_enable, + packet_enable => fx3_control.packet, + tx_fifo_write => tx_sample_fifo.wreq, + tx_fifo_full => tx_sample_fifo.wfull, + tx_fifo_empty => tx_sample_fifo.wempty, + tx_fifo_usedw => tx_sample_fifo.wused, + tx_fifo_data => tx_sample_fifo.wdata, + tx_timestamp => tx_timestamp, + tx_meta_fifo_write => tx_meta_fifo.wreq, + tx_meta_fifo_full => tx_meta_fifo.wfull, + tx_meta_fifo_empty => tx_meta_fifo.wempty, + tx_meta_fifo_usedw => tx_meta_fifo.wused, + tx_meta_fifo_data => tx_meta_fifo.wdata, + rx_fifo_read => rx_sample_fifo.rreq, + rx_fifo_full => rx_sample_fifo.rfull, + rx_fifo_empty => rx_sample_fifo.rempty, + rx_fifo_usedw => rx_sample_fifo.rused, + rx_fifo_data => rx_sample_fifo.rdata, + rx_meta_fifo_read => rx_meta_fifo.rreq, + rx_meta_fifo_full => rx_meta_fifo.rfull, + rx_meta_fifo_empty => rx_meta_fifo.rempty, + rx_meta_fifo_usedr => rx_meta_fifo.rused, + rx_meta_fifo_data => rx_meta_fifo.rdata + ); + + -- Discrete control signals for fx3_gpif + fx3_control.usb_speed <= '0'; + fx3_control.meta_enable <= '0'; + fx3_control.packet <= '0'; + + U_pkt_gen : entity nuand.rx_packet_generator + port map( + rx_clock => rx_clock, + rx_reset => rx_reset, + + rx_enable => fx3_control.rx_enable, + rx_packet_enable => fx3_control.packet, + + rx_packet_ready => rx_packet_ready, + + rx_packet_control => rx_packet_control + + ); + + + meta_en_tx <= fx3_control.meta_enable; + meta_en_rx <= fx3_control.meta_enable; + + increment_tx_ts : process(tx_clock) + variable ping : boolean := true ; + begin + if( rising_edge(tx_clock) ) then + ping := not ping ; + if( ping = true ) then + tx_timestamp <= tx_timestamp + 1 ; + end if ; + end if ; + end process ; + + increment_rx_ts : process(rx_clock) + variable ping : boolean := true ; + begin + if( rising_edge(rx_clock) ) then + ping := not ping ; + if( ping = true ) then + rx_timestamp <= rx_timestamp + 1 ; + end if ; + end if ; + end process ; + + -- Model of FX3's GPIF interface + -- Clock domain: fx3_pclk (source) + U_fx3_model : entity nuand.fx3_model(micro_dma_fifo_stress) + port map ( + fx3_pclk => fx3_pclk, + fx3_gpif => fx3_gpif_i, + fx3_ctl => fx3_ctl_i, + fx3_uart_rxd => '0', + fx3_uart_txd => open, + fx3_uart_cts => open, + fx3_rx_en => '1', + fx3_rx_meta_en => meta_en_rx, + fx3_tx_en => '1', + fx3_tx_meta_en => meta_en_tx, + eight_bit_mode_en => EIGHT_BIT_MODE_EN, + done => done + ); + + -- Generate phase-shifted PLL clock + U_fx3_pll : entity rtl_work.fx3_pll + port map ( + inclk0 => fx3_pclk, + areset => pll_reset, + c0 => fx3_pclk_pll, + locked => pll_locked + ); + + tx_clock <= not tx_clock after TX_HALF_PERIOD ; + rx_clock <= not rx_clock after RX_HALF_PERIOD ; + + + -- Reset handler + sys_rst <= '0' after 100 ns; + + -- Generate system clock + sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0'; + + + tx_reset <= sys_rst; + tx_ts_reset <= sys_rst; + rx_reset <= sys_rst; + rx_ts_reset <= sys_rst; + + meta_en_tx <= fx3_control.meta_enable; + meta_en_rx <= fx3_control.meta_enable; + + -- TX Submodule + U_tx : entity work.tx + generic map ( + NUM_STREAMS => dac_controls'length + ) + port map ( + tx_reset => tx_reset, + tx_clock => tx_clock, + tx_enable => fx3_control.tx_enable, + + meta_en => meta_en_tx, + timestamp_reset => tx_ts_reset, + usb_speed => fx3_control.usb_speed, + tx_underflow_led => open, + tx_timestamp => tx_timestamp, + + -- Triggering + trigger_arm => '0', + trigger_fire => '0', + trigger_master => '0', + trigger_line => open, + + -- Packet FIFO + packet_en => fx3_control.packet, + packet_empty => open, + packet_control => tx_packet_control, + packet_ready => '1', + + -- 8-bit mode + eight_bit_mode_en => EIGHT_BIT_MODE_EN, + + -- Samples from host via FX3 + sample_fifo_wclock => fx3_pclk_pll, + sample_fifo_wreq => tx_sample_fifo.wreq, + sample_fifo_wdata => tx_sample_fifo.wdata, + sample_fifo_wempty => tx_sample_fifo.wempty, + sample_fifo_wfull => tx_sample_fifo.wfull, + sample_fifo_wused => tx_sample_fifo.wused, + + -- Metadata from host via FX3 + meta_fifo_wclock => fx3_pclk_pll, + meta_fifo_wreq => tx_meta_fifo.wreq, + meta_fifo_wdata => tx_meta_fifo.wdata, + meta_fifo_wempty => tx_meta_fifo.wempty, + meta_fifo_wfull => tx_meta_fifo.wfull, + meta_fifo_wused => tx_meta_fifo.wused, + + -- Digital Loopback Interface + loopback_enabled => '0', + loopback_fifo_wdata => loopback_fifo.wdata, + loopback_fifo_wreq => loopback_fifo.wreq, + loopback_fifo_wfull => loopback_fifo.wfull, + loopback_fifo_wused => loopback_fifo.wused, + + -- RFFE Interface + dac_controls => dac_controls, + dac_streams => dac_streams + ); + + -- RX Submodule + U_rx : entity work.rx + generic map ( + NUM_STREAMS => adc_controls'length + ) + port map ( + rx_reset => rx_reset, + rx_clock => rx_clock, + rx_enable => fx3_control.rx_enable, + + meta_en => meta_en_rx, + timestamp_reset => rx_ts_reset, + usb_speed => fx3_control.usb_speed, + rx_mux_sel => to_unsigned(0, 3), + rx_overflow_led => open, + rx_timestamp => rx_timestamp, + + -- Triggering + trigger_arm => '0', + trigger_fire => '0', + trigger_master => '0', + trigger_line => open, + trigger_signal_sync_tb => trigger_signal_sync_tb, + + -- Packet FIFO + packet_en => fx3_control.packet, + packet_control => rx_packet_control, + packet_ready => rx_packet_ready, + + -- 8-bit mode + eight_bit_mode_en => EIGHT_BIT_MODE_EN, + + -- Samples to host via FX3 + sample_fifo_rclock => fx3_pclk_pll, + sample_fifo_raclr => not fx3_control.rx_enable, + sample_fifo_rreq => rx_sample_fifo.rreq, + sample_fifo_rdata => rx_sample_fifo.rdata, + sample_fifo_rempty => rx_sample_fifo.rempty, + sample_fifo_rfull => rx_sample_fifo.rfull, + sample_fifo_rused => rx_sample_fifo.rused, + + -- Mini expansion signals + mini_exp => "00", + + -- Metadata to host via FX3 + meta_fifo_rclock => fx3_pclk_pll, + meta_fifo_raclr => not fx3_control.rx_enable, + meta_fifo_rreq => rx_meta_fifo.rreq, + meta_fifo_rdata => rx_meta_fifo.rdata, + meta_fifo_rempty => rx_meta_fifo.rempty, + meta_fifo_rfull => rx_meta_fifo.rfull, + meta_fifo_rused => rx_meta_fifo.rused, + + -- Digital Loopback Interface + loopback_fifo_wenabled => open, + loopback_fifo_wreset => tx_reset, + loopback_fifo_wclock => tx_clock, + loopback_fifo_wdata => loopback_fifo.wdata, + loopback_fifo_wreq => loopback_fifo.wreq, + loopback_fifo_wfull => loopback_fifo.wfull, + loopback_fifo_wused => loopback_fifo.wused, + + -- RFFE Interface + adc_controls => adc_controls, + adc_streams => adc_streams + ); + + -- ======================================================================== + -- Data converters + -- ======================================================================== + + gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate + -- The TX side of the AD9361 HDL is a FIFO pull interface + -- that expects a readahead FIFO. It toggles the data request + -- signal every other cycle. This behavior is mimicked here. + process( tx_clock, sys_rst ) + begin + if( sys_rst = '1' ) then + dac_controls <= ( + 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'), + 1 => (enable => ENABLE_CHANNEL_1, data_req => '1') + ); + elsif( rising_edge(tx_clock) ) then + for i in dac_controls'range loop + dac_controls(i) <= ( + enable => dac_controls(i).enable, + data_req => not dac_controls(i).data_req ); + end loop; + end if; + end process; + else generate + dac_controls <= (others => SAMPLE_CONTROL_ENABLE); + end generate; + + gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate + process( rx_clock, sys_rst ) + constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000"; + constant COUNT_RESET : integer := 0; + variable count : integer range -2047 to 2047 := COUNT_RESET; + begin + if( sys_rst = '1' ) then + count := COUNT_RESET; + adc_controls <= ( + 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'), + 1 => (enable => ENABLE_CHANNEL_1, data_req => '1') + ); + elsif( rising_edge(rx_clock) ) then + for i in adc_controls'range loop + adc_controls(i) <= ( + enable => adc_controls(i).enable, + data_req => not adc_controls(i).data_req ); + if( adc_controls(i).enable = '1') then + if( adc_streams(i).data_v = '1' ) then + if( EIGHT_BIT_MODE_EN = '1' ) then + adc_streams(i).data_i <= "0000" & to_signed(count, 8) & SIGMA_DELTA_BITS; + adc_streams(i).data_q <= "0000" & to_signed(-count, 8) & SIGMA_DELTA_BITS; + count := (count + 1) mod 128; + else + adc_streams(i).data_i <= to_signed(count, 16); + adc_streams(i).data_q <= to_signed(-count, 16); + count := (count + 1) mod 2048; + end if; + end if; + adc_streams(i).data_v <= not adc_streams(i).data_v; + end if; + end loop; + end if; + end process; + else generate + adc_controls <= (others => SAMPLE_CONTROL_ENABLE); + end generate; + + -- ======================================================================== + -- Processes + -- ======================================================================== + + -- FX3 GPIF bidirectional signal control + -- Adapted from same process in bladerf-hosted.vhd + register_gpif : process(sys_rst, fx3_pclk_pll) + begin + if( sys_rst = '1' ) then + fx3_gpif_i <= (others => 'Z'); + fx3_gpif.gpif_in <= (others => 'Z'); + elsif( rising_edge(fx3_pclk_pll) ) then + fx3_gpif.gpif_in <= fx3_gpif_i; + + if( fx3_gpif.gpif_oe = '1' ) then + fx3_gpif_i <= fx3_gpif.gpif_out; + else + fx3_gpif_i <= (others =>'Z'); + end if; + end if; + end process; + + -- FX3 CTL bidirectional signals + -- Adapted from same generator in bladerf-hosted.vhd + generate_ctl : for i in fx3_ctl_i'range generate + fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z'; + end generate; + + fx3_gpif.ctl_in <= fx3_ctl_i; + + -- Controller for loopback FIFO + -- Stripped-down version of same process from rx.vhd + loopback_fifo_control : process( sys_rst, loopback_fifo.rclock ) + begin + if( sys_rst = '1' ) then + loopback_enabled <= '0'; + loopback_fifo.rreq <= '0'; + loopback_i <= (others => '0'); + loopback_q <= (others => '0'); + loopback_valid <= '0'; + elsif( rising_edge(loopback_fifo.rclock) ) then + loopback_enabled <= '0'; + loopback_fifo.rreq <= '0'; + loopback_i <= loopback_i; + loopback_q <= loopback_q; + loopback_valid <= '0'; + + -- Is loopback enabled? + loopback_enabled <= fx3_control.rx_enable; + + -- Do the loopback + loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length); + loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length); + loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty; + + -- Read from the FIFO if req'd + loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty); + end if; + end process; + + -- RX multiplexer + -- Stripped-down version of same process from rx.vhd + rx_mux : process(sys_rst, sys_clk) + begin + if( sys_rst = '1' ) then + rx_mux_i <= (others =>'0'); + rx_mux_q <= (others =>'0'); + rx_mux_valid <= '0'; + elsif( rising_edge(sys_clk) ) then + rx_mux_i <= loopback_i; + rx_mux_q <= loopback_q; + rx_mux_valid <= loopback_valid; + end if; + end process; + + -- TX multiplexer + -- Stripped-down version of mimo_channel_sel_mux from tx.vhd + --tx_mux : process( sys_clk ) + --begin + -- if( rising_edge(sys_clk) ) then + -- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty; + + -- loopback_fifo.wdata <= tx_sample_fifo.rdata; + -- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty; + -- end if; + --end process; + + + -- ======================================================================== + -- Verification + -- ======================================================================== + print_config: process + begin + wait until rising_edge(fx3_control.tx_enable); + report lf& + "[CONFIG] EIGHT_BIT_MODE_EN: " & std_logic'image(EIGHT_BIT_MODE_EN) &lf& + "[CONFIG] ENABLE_CHANNEL_0: " & std_logic'image(ENABLE_CHANNEL_0) &lf& + "[CONFIG] ENABLE_CHANNEL_1: " & std_logic'image(ENABLE_CHANNEL_1); + end process print_config; + + + -- + -- Check for metavalues + -- We should never see metavalues written to the FIFOs + -- + check_fifo_write : process(fx3_pclk_pll) is + begin + if( rising_edge(fx3_pclk_pll) ) then + if( tx_sample_fifo.wreq = '1' and fx3_control.meta_enable = '0' ) then + for i in tx_sample_fifo.wdata'range loop + assert tx_sample_fifo.wdata(i) = '0' or tx_sample_fifo.wdata(i) = '1' + severity failure; + end loop; + end if; + end if; + end process; + + check_fifo_read : process(fx3_pclk_pll) is + begin + if( rising_edge(fx3_pclk_pll) ) then + if( rx_sample_fifo.rreq = '1' ) then + for i in rx_sample_fifo.rdata'range loop + assert rx_sample_fifo.rdata(i) = '0' or rx_sample_fifo.rdata(i) = '1' + severity failure; + end loop; + end if; + end if; + end process check_fifo_read; + + -- + -- Check for fullness on FIFOs + -- + assert(rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning; + assert(tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning; + assert(loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning; + + -- + -- Tx Sample Check + -- + look_for_dropped_tx_samples : process(tx_clock) is + constant MESSAGES_PER_ITERATION : natural := 7; --Provided in fx3_model + constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000"; + variable current_message_count : natural := 1; + variable iq_value : signed (15 downto 0) := x"0000"; + variable expected_sample_i : signed (15 downto 0); + variable expected_sample_q : signed (15 downto 0); + variable failure_count : natural := 0; + begin + for i in dac_controls'range loop + if( rising_edge(tx_clock) + and dac_controls(i).enable = '1' + and dac_streams(i).data_v = '1' + and fx3_control.tx_enable = '1' ) + then + if( EIGHT_BIT_MODE_EN = '1' ) then + expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS; + expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS; + + assert ( dac_streams(i).data_i = expected_sample_i ) + report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " & + "expected_sample_i: " & to_hstring(expected_sample_i) + severity warning; + assert ( dac_streams(i).data_q = expected_sample_q ) + report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " & + "expected_sample_q: " & to_hstring(expected_sample_q) + severity warning; + + if ( dac_streams(i).data_i /= expected_sample_i or dac_streams(i).data_q /= expected_sample_q ) then + failure_count := failure_count + 1; + if ( failure_count >= 6 ) then + report "tx fail count tolerance exceeded" severity failure; + end if; + end if; + + iq_value := (iq_value + 2) mod 128; + else + expected_sample_i := iq_value; + expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1); + + assert(dac_streams(i).data_i = expected_sample_i) + report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " & + "expected_sample_i: " & to_hstring(expected_sample_i) + severity failure; + assert(dac_streams(i).data_q = expected_sample_q) + report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " & + "expected_sample_q: " & to_hstring(expected_sample_q) + severity failure; + + -- Set iq values based on blocks received + -- See tx_sample_stream's encoding scheme in fx3_model.vhd + if( iq_value = x"03FE" ) then + iq_value := x"0000"; + if( current_message_count < MESSAGES_PER_ITERATION ) then + current_message_count := current_message_count + 1; + else + current_message_count := 1; + end if; + else + iq_value := (iq_value + 2) mod 2048; + end if; + end if; + end if; + end loop; + + end process look_for_dropped_tx_samples; + + -- + -- Rx Sample Check + -- + first_rx_val_at_mux: process + -- Catches and saves the first sample of + -- each rx enabled burst seen by the mux + begin + for i in adc_controls'range loop + if( adc_controls(i).enable = '1') then + if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1' ) then + adc_stream_val_at_rx_enable <= adc_streams(i).data_i - 1; + else + adc_stream_val_at_rx_enable <= adc_streams(i).data_i; + end if; + end if; + end loop; + wait until rising_edge(trigger_signal_sync_tb); + end process first_rx_val_at_mux; + + look_for_dropped_rx_samples: process(fx3_pclk_pll) + variable rx_val : integer := 0; + + variable q_expected : std_logic_vector (15 downto 0); + variable i_expected : std_logic_vector (15 downto 0); + variable q_out : std_logic_vector (15 downto 0); + variable i_out : std_logic_vector (15 downto 0); + + variable q0_expected_eight_bit_mode : std_logic_vector (7 downto 0); + variable i0_expected_eight_bit_mode : std_logic_vector (7 downto 0); + variable q1_expected_eight_bit_mode : std_logic_vector (7 downto 0); + variable i1_expected_eight_bit_mode : std_logic_vector (7 downto 0); + variable q0_out_eight_bit_mode : std_logic_vector (7 downto 0); + variable i0_out_eight_bit_mode : std_logic_vector (7 downto 0); + variable q1_out_eight_bit_mode : std_logic_vector (7 downto 0); + variable i1_out_eight_bit_mode : std_logic_vector (7 downto 0); + + variable previous_adc_stream_val_at_rx_enable : signed (15 downto 0) := ( others => '0'); + variable fail_count: natural := 0; + variable both_channels_en : std_logic; + begin + if( previous_adc_stream_val_at_rx_enable /= adc_stream_val_at_rx_enable ) then + rx_val := to_integer(adc_stream_val_at_rx_enable (15 downto 4)) when EIGHT_BIT_MODE_EN else + to_integer(adc_stream_val_at_rx_enable); + previous_adc_stream_val_at_rx_enable := adc_stream_val_at_rx_enable; + end if; + + if( rising_edge(fx3_pclk_pll) + and fx3_gpif.gpif_oe = '1' + and fx3_control.rx_enable = '1' ) then + if( EIGHT_BIT_MODE_EN = '1') then + -- The +-1 ch1 offset in SISO mode will not reach 128 + both_channels_en := ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1; + q1_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val - 1, 8)) when both_channels_en else + std_logic_vector(to_signed(-((rx_val + 1) mod 128), 8)); + i1_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val + 1, 8)) when both_channels_en else + std_logic_vector(to_signed((rx_val + 1) mod 128, 8)); + q0_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val, 8)); + i0_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val, 8)); + + q1_out_eight_bit_mode := fx3_gpif.gpif_out(31 downto 24); + i1_out_eight_bit_mode := fx3_gpif.gpif_out(23 downto 16); + q0_out_eight_bit_mode := fx3_gpif.gpif_out(15 downto 8); + i0_out_eight_bit_mode := fx3_gpif.gpif_out(7 downto 0); + + if( q1_out_eight_bit_mode /= q1_expected_eight_bit_mode or + i1_out_eight_bit_mode /= i1_expected_eight_bit_mode or + q0_out_eight_bit_mode /= q0_expected_eight_bit_mode or + i0_out_eight_bit_mode /= i0_expected_eight_bit_mode) then + fail_count := fail_count + 1; + report "-----------------------------"; + if( fail_count > 3 ) then + report "rx fail count tolerance exceeded" severity failure; + end if; + end if; + + assert ( q1_out_eight_bit_mode = q1_expected_eight_bit_mode ) + report "data_q1: " & to_hstring(q1_out_eight_bit_mode) & " | " & + "expected: " & to_hstring(q1_expected_eight_bit_mode) + severity warning; + assert ( i1_out_eight_bit_mode = i1_expected_eight_bit_mode ) + report "data_i1: " & to_hstring(i1_out_eight_bit_mode) & " | " & + "expected: " & to_hstring(i1_expected_eight_bit_mode) + severity warning; + assert ( q0_out_eight_bit_mode = q0_expected_eight_bit_mode ) + report "data_q0: " & to_hstring(q0_out_eight_bit_mode) & " | " & + "expected: " & to_hstring(q0_expected_eight_bit_mode) + severity warning; + assert ( i0_out_eight_bit_mode = i0_expected_eight_bit_mode ) + report "data_i0: " & to_hstring(i0_out_eight_bit_mode) & " | " & + "expected: " & to_hstring(i0_expected_eight_bit_mode) + severity warning; + + -- 128 limit set by gen_adc_controls above + rx_val := (rx_val + 2) mod 128; + else + q_expected := std_logic_vector(to_signed(-rx_val, 16)); + i_expected := std_logic_vector(to_signed(rx_val, 16)); + q_out := fx3_gpif.gpif_out(31 downto 16); + i_out := fx3_gpif.gpif_out(15 downto 0); + + assert(q_out = q_expected) + report "data_q: " & to_hstring(q_out) & " | " & + "expected: " & to_hstring(q_expected) + severity failure; + assert(i_out = i_expected) + report "data_i: " & to_hstring(i_out) & " | " & + "expected: " & to_hstring(i_expected) + severity failure; + + -- 2047 limit set by gen_adc_controls above + rx_val := (rx_val + 1) mod 2048; + end if; + end if; + end process look_for_dropped_rx_samples; + +end architecture; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd new file mode 100644 index 00000000..21e3618b --- /dev/null +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd @@ -0,0 +1,279 @@ +-- Copyright (c) 2024 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. + +library ieee; + use ieee.std_logic_1164.all; + use ieee.numeric_std.all; + use ieee.math_real.all; + use ieee.math_complex.all; + +library work; + use work.util.all; + +architecture micro_dma_fifo_stress of fx3_model is + + constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0); + constant START_COUNT : natural := 32; + constant BLOCKS_PER_ITERATION : natural := 7; + constant ITERATIONS : natural := 4; + + -- Control mapping + alias dma0_rx_ack is fx3_ctl( 0); + alias dma1_rx_ack is fx3_ctl( 1); + alias dma2_tx_ack is fx3_ctl( 2); + alias dma3_tx_ack is fx3_ctl( 3); + alias dma_rx_enable is fx3_ctl( 4); + alias dma_tx_enable is fx3_ctl( 5); + alias dma_idle is fx3_ctl( 6); + alias system_reset is fx3_ctl( 7); + alias dma0_rx_reqx is fx3_ctl( 8); + alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk + alias dma2_tx_reqx is fx3_ctl(10); + alias dma3_tx_reqx is fx3_ctl(11); + + type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES); + signal gpif_state_rx, gpif_state_tx : gpif_state_t; + + signal rx_done : boolean := false; + signal tx_done : boolean := false; + + signal rx_data : std_logic_vector(31 downto 0); + signal tx_data : std_logic_vector(31 downto 0); + + impure function data_gen (count : natural) return std_logic_vector is + variable eight_bit_msw_i : std_logic_vector(7 downto 0); + variable eight_bit_msw_q : std_logic_vector(7 downto 0); + variable eight_bit_lsw_i : std_logic_vector(7 downto 0); + variable eight_bit_lsw_q : std_logic_vector(7 downto 0); + variable msw, lsw : std_logic_vector(15 downto 0); + begin + if( eight_bit_mode_en = '1' ) then + eight_bit_lsw_i := std_logic_vector(to_unsigned(count, 8)); + eight_bit_lsw_q := std_logic_vector(to_unsigned(count+1, 8)); + eight_bit_msw_i := std_logic_vector(to_unsigned(count+2, 8)); + eight_bit_msw_q := std_logic_vector(to_unsigned(count+3, 8)); + lsw := eight_bit_lsw_q & eight_bit_lsw_i; + msw := eight_bit_msw_q & eight_bit_msw_i; + else + msw := std_logic_vector(to_signed(count+1, 16)); + lsw := std_logic_vector(to_signed(count, 16)); + end if; + + return (msw & lsw); + end function data_gen; + + impure function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is + begin + return (rxdata = data_gen(count)); + end function data_check; + +begin + + -- DCLK which isn't used + fx3_ctl(9) <= '0'; + + fx3_ctl(3 downto 0) <= (others => 'Z'); + + -- Create a 100MHz clock output + fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0'; + + -- Doneness + done <= rx_done and tx_done; + + rx_sample_stream : process + constant BLOCK_SIZE : natural := 512; + variable count : natural := START_COUNT; + variable req_time : time; + begin + gpif_state_rx <= IDLE; + dma0_rx_reqx <= '1'; + dma1_rx_reqx <= '1'; + dma_rx_enable <= '0'; + rx_data <= (others => 'U'); + + wait until rising_edge(fx3_pclk) and system_reset = '0'; + + nop(fx3_pclk, 1000); + + wait until rising_edge(fx3_pclk) and fx3_rx_en = '1'; + + wait for 30 us; + + for j in 1 to ITERATIONS loop + dma_rx_enable <= '1'; + + for i in 1 to BLOCKS_PER_ITERATION loop + dma0_rx_reqx <= '0'; + req_time := now; + wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1'; + wait until rising_edge( fx3_pclk ); + dma0_rx_reqx <= '1'; + + report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time); + + for i in 1 to BLOCK_SIZE loop + gpif_state_rx <= RX_SAMPLES; + rx_data <= fx3_gpif; + wait until rising_edge( fx3_pclk ); + + --assert data_check(count, rx_data) severity failure; + + count := (count + 1) mod 2048; + gpif_state_rx <= IDLE; + rx_data <= (others => 'X'); + end loop; + end loop; + + dma_rx_enable <= '0'; + wait for 10 us; + end loop; + + report "Done with RX sample stream"; + rx_done <= true; + wait; + end process; + + tx_sample_stream : process + constant TIME_BETWEEN_ITERATIONS : natural := 4593; + constant BLOCK_SIZE : natural := 512; + variable count : natural := START_COUNT; + variable timestamp_cntr : natural := 400; + variable header_len : natural := 0; + variable data_out : std_logic_vector(31 downto 0); + variable req_time : time; + begin + gpif_state_tx <= IDLE; + dma2_tx_reqx <= '1'; + dma3_tx_reqx <= '1'; + dma_tx_enable <= '0'; + fx3_gpif <= (others =>'Z'); + + wait until rising_edge(fx3_pclk) and system_reset = '0'; + + nop(fx3_pclk, 1000); + + wait until rising_edge(fx3_pclk) and fx3_tx_en = '1'; + + wait for 30 us; + + for k in 1 to ITERATIONS loop + dma_tx_enable <= '1'; + + for fifo_stress_idx in 1 to 3 loop + for j in 1 to BLOCKS_PER_ITERATION loop + header_len := 0; + dma3_tx_reqx <= '0'; + req_time := now; + wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1'; + wait until rising_edge( fx3_pclk ); + wait until rising_edge( fx3_pclk ); + wait until rising_edge( fx3_pclk ); + dma3_tx_reqx <= '1'; + + report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time); + + + if( fx3_tx_meta_en = '1') then + header_len := 4; + + for i in 1 to 4 loop + case (i) is + when 1 => + data_out := x"00000000"; + when 2 => + data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32)); + if (j = BLOCKS_PER_ITERATION) then + timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS; + else + timestamp_cntr := timestamp_cntr + 254; + end if; + when 3 => + data_out := (others => '0'); + when 4 => + data_out := (others => '1'); + end case; + + gpif_state_tx <= TX_META; + fx3_gpif <= data_out; + tx_data <= data_out; + wait until rising_edge( fx3_pclk ); + + gpif_state_tx <= IDLE; + tx_data <= (others => 'X'); + end loop; + end if; + count := 0; + + for i in 1 to (BLOCK_SIZE - header_len) loop + gpif_state_tx <= TX_SAMPLES; + data_out := data_gen(count); + if( eight_bit_mode_en = '1' ) then + fx3_gpif <= data_out; + tx_data <= data_out; + else + fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); + tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); + end if; + wait until rising_edge( fx3_pclk ); + + count := (count + 4) mod 128 when eight_bit_mode_en = '1' else + (count + 2) mod 2048; + gpif_state_tx <= IDLE; + tx_data <= (others => 'X'); + end loop; + + fx3_gpif <= (others =>'Z'); + nop(fx3_pclk, 10); + end loop; + wait for 10 us; + end loop; + + wait for 2 ms; + dma_tx_enable <= '0'; + wait for 10 us; + end loop; + + report "Done with TX sample stream"; + tx_done <= true; + wait; + end process; + + reset_system : process + begin + system_reset <= '1'; + dma_idle <= '0'; + nop( fx3_pclk, 100 ); + system_reset <= '0'; + nop( fx3_pclk, 10 ); + dma_idle <= '1'; + wait; + end process; + + -- TODO: UART Interface + fx3_uart_txd <= '1'; + fx3_uart_cts <= '1'; + + assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE) + or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE) + or (gpif_state_rx = IDLE and gpif_state_tx = IDLE) + report "gpif_state_rx and gpif_state_tx cannot both be non-idle" + severity failure; + +end architecture micro_dma_fifo_stress; From b20607fd827ec79546e2cca127b10fc8793ee05f Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 24 Jul 2024 13:08:40 -0500 Subject: [PATCH 07/41] hdl: fixed fifo ingestion arithmetic on tx enable toggle The channel shift would be left at 1 after the state moved to COMPUTE_ENABLED_CHANNELS. Samples left would be reassigned to 1 in COMPUTE_OFFSETS. Then channel offset would be assigned 2, an invalid value. This change only assigns samples left and channel shift if at the 0th sample index, which allows for sample continuity. --- hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd index d4cfb406..a8c5ddb7 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd @@ -493,7 +493,11 @@ begin -- still need to be processed (not including the first). This becomes the number of clock -- cycles to wait before asserting the FIFO read request to get a new batch of samples. fifo_future.samples_left_init <= NUM_STREAMS - fifo_current.enabled_channels; - fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels; + + if (fifo_current.samples_left = FIFO_FSM_RESET_VALUE.samples_left) then + fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels; + fifo_future.ch_shift <= 0; + end if; if( packet_en = '1' ) then fifo_future.state <= READ_PACKET; From 0dd41a3fa5c8ed105ac15e5e16f54f4d1e253474 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 23 Jul 2024 19:24:26 -0500 Subject: [PATCH 08/41] hdl: leverage full sample depth of sample fifos We were limiting ourselves to half of the fifo depth and subtracting 4 gpif buffers from that, which is 1/4 of the current fifo depth. No sign of a full fifo during siso, mimo, meta, and non-meta streaming tests at low sample rates. The fifo writes are appropriately held off. --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 2 +- hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd | 8 ++++---- hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index 86bf18d3..f4667b34 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -187,7 +187,7 @@ begin meta_fifo_used_v := unsigned(meta_fifo_full & meta_fifo_usedw); meta_fifo_used_v_r <= meta_fifo_used_v; - if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size * 4 )) and + if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size )) and ( ( meta_en = '1' and meta_fifo_full = '0' and ( META_MAX - 4 ) > meta_fifo_used_v_r ) or (meta_en = '0') ) ) then fifo_enough <= true; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd index 519d57db..4aa6ee3c 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd @@ -168,11 +168,11 @@ package bladerf_p is constant TX_FIFO_WWIDTH : natural := 32; -- write side data width constant TX_FIFO_RWIDTH : natural := 64; -- read side data width - constant TX_FIFO_LENGTH : natural := 16384; -- samples + constant TX_FIFO_LENGTH : natural := 8192; -- samples constant RX_FIFO_WWIDTH : natural := 64; -- write side data width constant RX_FIFO_RWIDTH : natural := 32; -- read side data width - constant RX_FIFO_LENGTH : natural := 4096; -- samples + constant RX_FIFO_LENGTH : natural := 8192; -- samples constant ADSB_FIFO_WWIDTH : natural := 128; -- write side data width constant ADSB_FIFO_RWIDTH : natural := 32; -- read side data width @@ -184,11 +184,11 @@ package bladerf_p is constant META_FIFO_TX_WWIDTH : natural := 32; -- write side data width constant META_FIFO_TX_RWIDTH : natural := 128; -- read side data width - constant META_FIFO_TX_LENGTH : natural := 512; -- 32-bit words + constant META_FIFO_TX_LENGTH : natural := 2048; -- 32-bit words constant META_FIFO_RX_WWIDTH : natural := 128; -- write side data width constant META_FIFO_RX_RWIDTH : natural := 32; -- read side data width - constant META_FIFO_RX_LENGTH : natural := 512; -- 32-bit words + constant META_FIFO_RX_LENGTH : natural := 2048; -- 32-bit words type tx_fifo_t is record aclr : std_logic; diff --git a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd index dfdf0417..67380194 100644 --- a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd +++ b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd @@ -280,7 +280,7 @@ begin -- Can we not fit one more block of data in RX buffer? rx_fifo_critical <= (unsigned(rx_fifo_usedw) >= ((2**(rx_fifo_usedw'length-1) - gpif_buf_size))); -- Do we have room for one more block of data in the TX buffer? - tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length-1) - gpif_buf_size * 4))) and + tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length) - gpif_buf_size))) and (unsigned(tx_meta_fifo_usedw) < ((2**(tx_meta_fifo_usedw'length-1) - 4))); end if; end process calculate_fifo_waterlines; From 3c8bf68067ea9195d1fc6ddbef86c4c1fcae14a3 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 29 Jul 2024 14:44:31 -0500 Subject: [PATCH 09/41] hdl: moved gpif buf size constants to fx3 gpif package As we add changes to the FX3, it will be much easier to have a single source of truth for the GPIF DMA sizes. This commit should not introduce any changes to simulation or synthesis results. --- hdl/fpga/ip/nuand/fx3_gpif_tb.do | 1 + hdl/fpga/ip/nuand/nuand.do | 1 + hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd | 5 ++-- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 5 ++-- .../platforms/bladerf-micro/bladerf-adsb.qip | 1 + .../bladerf-micro/bladerf-foxhunt.qip | 1 + .../bladerf-micro/bladerf-hosted.qip | 1 + .../platforms/bladerf-micro/bladerf-wlan.qip | 1 + .../bladerf-micro/modelsim/compile.do | 1 + hdl/fpga/platforms/bladerf/bladerf-adsb.qip | 1 + .../platforms/bladerf/bladerf-atsc_tx.qip | 1 + hdl/fpga/platforms/bladerf/bladerf-hosted.qip | 1 + .../common/bladerf/vhdl/fx3_gpif.vhd | 7 +++-- .../common/bladerf/vhdl/fx3_gpif_p.vhd | 27 +++++++++++++++++++ 14 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd diff --git a/hdl/fpga/ip/nuand/fx3_gpif_tb.do b/hdl/fpga/ip/nuand/fx3_gpif_tb.do index 1b3cc47b..5b70254d 100644 --- a/hdl/fpga/ip/nuand/fx3_gpif_tb.do +++ b/hdl/fpga/ip/nuand/fx3_gpif_tb.do @@ -4,6 +4,7 @@ proc compile_fx3_gpif { root } { vlib work vcom -2008 -work work [file join $root ./synthesis/set_clear_ff.vhd] + vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd] vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif.vhd] vcom -2008 -work work [file join $root ./simulation/util.vhd] vcom -2008 -work work [file join $root ./simulation/fx3_model.vhd] diff --git a/hdl/fpga/ip/nuand/nuand.do b/hdl/fpga/ip/nuand/nuand.do index c1475459..1d530437 100644 --- a/hdl/fpga/ip/nuand/nuand.do +++ b/hdl/fpga/ip/nuand/nuand.do @@ -42,6 +42,7 @@ proc compile_nuand { root platform } { vcom -work nuand -2008 [file join $root ./synthesis/tb/atsc_tx_tb.vhd] + vcom -work nuand -2008 [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd] vcom -work nuand -2008 [file join $root ./simulation/fx3_model.vhd] vcom -work nuand -2008 [file join $root ./simulation/lms6002d_model.vhd] diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd index a8c5ddb7..848155ea 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd @@ -24,6 +24,7 @@ library ieee; library work; use work.fifo_readwrite_p.all; + use work.fx3_gpif_p.all; entity fifo_reader is generic ( @@ -71,8 +72,8 @@ end entity; architecture simple of fifo_reader is - constant DMA_BUF_SIZE_SS : natural := 512; - constant DMA_BUF_SIZE_HS : natural := 256; + constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS; + constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS; signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS; signal underflow_detected : std_logic := '0'; diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index f4667b34..36fa0098 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -24,6 +24,7 @@ library ieee; library work; use work.fifo_readwrite_p.all; + use work.fx3_gpif_p.all; entity fifo_writer is generic ( @@ -70,8 +71,8 @@ end entity; architecture simple of fifo_writer is - constant DMA_BUF_SIZE_SS : natural := 512; - constant DMA_BUF_SIZE_HS : natural := 256; + constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS; + constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS; signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS; diff --git a/hdl/fpga/platforms/bladerf-micro/bladerf-adsb.qip b/hdl/fpga/platforms/bladerf-micro/bladerf-adsb.qip index 51720fcf..f6ac9da8 100644 --- a/hdl/fpga/platforms/bladerf-micro/bladerf-adsb.qip +++ b/hdl/fpga/platforms/bladerf-micro/bladerf-adsb.qip @@ -36,6 +36,7 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]] # Implementation Details +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx-adsb.vhd]] diff --git a/hdl/fpga/platforms/bladerf-micro/bladerf-foxhunt.qip b/hdl/fpga/platforms/bladerf-micro/bladerf-foxhunt.qip index 80b16c4a..380c3eea 100644 --- a/hdl/fpga/platforms/bladerf-micro/bladerf-foxhunt.qip +++ b/hdl/fpga/platforms/bladerf-micro/bladerf-foxhunt.qip @@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sy set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip tone_generator/tone_generator.qip]] # Implementation Details +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]] diff --git a/hdl/fpga/platforms/bladerf-micro/bladerf-hosted.qip b/hdl/fpga/platforms/bladerf-micro/bladerf-hosted.qip index 42f5e944..2a97c1c9 100644 --- a/hdl/fpga/platforms/bladerf-micro/bladerf-hosted.qip +++ b/hdl/fpga/platforms/bladerf-micro/bladerf-hosted.qip @@ -34,6 +34,7 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]] # Implementation Details +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]] diff --git a/hdl/fpga/platforms/bladerf-micro/bladerf-wlan.qip b/hdl/fpga/platforms/bladerf-micro/bladerf-wlan.qip index 4504b78a..d30315e2 100644 --- a/hdl/fpga/platforms/bladerf-micro/bladerf-wlan.qip +++ b/hdl/fpga/platforms/bladerf-micro/bladerf-wlan.qip @@ -36,6 +36,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synth set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip rfic_spi_controller/vhdl/rfic_spi_controller.vhd]] # Implementation Details +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]] diff --git a/hdl/fpga/platforms/bladerf-micro/modelsim/compile.do b/hdl/fpga/platforms/bladerf-micro/modelsim/compile.do index 61ada131..1c44b08b 100644 --- a/hdl/fpga/platforms/bladerf-micro/modelsim/compile.do +++ b/hdl/fpga/platforms/bladerf-micro/modelsim/compile.do @@ -3,6 +3,7 @@ compile_nuand ../../../ip/nuand bladerf-micro vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd +vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif.vhd vcom -work nuand -2008 ../vhdl/bladerf_p.vhd diff --git a/hdl/fpga/platforms/bladerf/bladerf-adsb.qip b/hdl/fpga/platforms/bladerf/bladerf-adsb.qip index 1fa86c44..02d157c0 100644 --- a/hdl/fpga/platforms/bladerf/bladerf-adsb.qip +++ b/hdl/fpga/platforms/bladerf/bladerf-adsb.qip @@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]] +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-adsb.vhd]] diff --git a/hdl/fpga/platforms/bladerf/bladerf-atsc_tx.qip b/hdl/fpga/platforms/bladerf/bladerf-atsc_tx.qip index a53653fb..15865fe0 100644 --- a/hdl/fpga/platforms/bladerf/bladerf-atsc_tx.qip +++ b/hdl/fpga/platforms/bladerf/bladerf-atsc_tx.qip @@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]] +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-atsc_tx.vhd]] set_global_assignment -name QIP_FILE [file normalize nios_system/synthesis/nios_system.qip] diff --git a/hdl/fpga/platforms/bladerf/bladerf-hosted.qip b/hdl/fpga/platforms/bladerf/bladerf-hosted.qip index 93cb2b28..0604d825 100644 --- a/hdl/fpga/platforms/bladerf/bladerf-hosted.qip +++ b/hdl/fpga/platforms/bladerf/bladerf-hosted.qip @@ -35,6 +35,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/bladerf_agc.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip trigger/trigger.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]] +set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/rx_packet_generator.vhd]] set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-hosted.vhd]] diff --git a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd index 67380194..bfdad067 100644 --- a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd +++ b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif.vhd @@ -22,6 +22,9 @@ library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; +library nuand; + use nuand.fx3_gpif_p.all; + entity fx3_gpif is port ( -- FX3 control signals @@ -117,10 +120,6 @@ architecture sample_shuffler of fx3_gpif is constant META_DOWNCOUNT_RESET : natural := 4; constant FINI_DOWNCOUNT_RESET : natural := 10; - -- GPIF buf sizes for USB high-speed and super-speed - constant GPIF_BUF_SIZE_HS : natural := 256; - constant GPIF_BUF_SIZE_SS : natural := 512; - type dma_handshake_t is record rx0 : std_logic; rx1 : std_logic; diff --git a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd new file mode 100644 index 00000000..43d7673c --- /dev/null +++ b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd @@ -0,0 +1,27 @@ +-- Copyright (c) 2024 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. +library ieee; +use ieee.std_logic_1164.all; + +package fx3_gpif_p is + -- GPIF buf sizes for USB high-speed and super-speed + constant GPIF_BUF_SIZE_HS : natural := 256; + constant GPIF_BUF_SIZE_SS : natural := 512; +end package fx3_gpif_p; From af67f86333af7eda23fa093c6cf863da7d81f753 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 12:04:17 -0500 Subject: [PATCH 10/41] hdl: test: added variable length gpif support to fx3_model --- hdl/fpga/ip/nuand/simulation/fx3_model.vhd | 8 +++++--- .../platforms/bladerf-micro/vhdl/tb/fx3_model.vhd | 13 +++++++------ hdl/fpga/platforms/bladerf/modelsim/compile.do | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hdl/fpga/ip/nuand/simulation/fx3_model.vhd b/hdl/fpga/ip/nuand/simulation/fx3_model.vhd index fc2da9e1..b13b55c1 100644 --- a/hdl/fpga/ip/nuand/simulation/fx3_model.vhd +++ b/hdl/fpga/ip/nuand/simulation/fx3_model.vhd @@ -26,6 +26,8 @@ library ieee; library work; use work.util.all; + use work.fx3_gpif_p.all; + entity fx3_model is port ( @@ -102,7 +104,7 @@ begin done <= rx_done and tx_done; rx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable req_time : time; begin @@ -155,7 +157,7 @@ begin end process; tx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable timestamp_cntr : natural := 80; variable header_len : natural := 0; @@ -201,7 +203,7 @@ begin data_out := x"12341234"; when 2 => data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32)); - timestamp_cntr := timestamp_cntr + 508 * 2; + timestamp_cntr := timestamp_cntr + (GPIF_BUF_SIZE_SS-4) * 2; when 3 => data_out := (others => '0'); when 4 => diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd index 29a39001..be1682a9 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd @@ -26,6 +26,7 @@ library ieee; library work; use work.util.all; + use work.fx3_gpif_p.all; architecture micro_dma of fx3_model is @@ -98,7 +99,7 @@ begin done <= rx_done and tx_done; rx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable req_time : time; begin @@ -151,8 +152,8 @@ begin end process; tx_sample_stream : process - constant TIME_BETWEEN_ITERATIONS : natural := 4593; - constant BLOCK_SIZE : natural := 512; + constant TIME_BETWEEN_ITERATIONS : natural := 7000; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable timestamp_cntr : natural := 400; variable header_len : natural := 0; @@ -242,7 +243,7 @@ begin nop(fx3_pclk, 10); end loop; - wait for 1 ms; + wait for 1.5 ms; dma_tx_enable <= '0'; wait for 10 us; end loop; @@ -333,7 +334,7 @@ begin done <= rx_done and tx_done; rx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable req_time : time; begin @@ -387,7 +388,7 @@ begin tx_sample_stream : process constant TIME_BETWEEN_ITERATIONS : natural := 4556; - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable timestamp_cntr : natural := 250; variable header_len : natural := 0; diff --git a/hdl/fpga/platforms/bladerf/modelsim/compile.do b/hdl/fpga/platforms/bladerf/modelsim/compile.do index 289bc60f..06e95382 100644 --- a/hdl/fpga/platforms/bladerf/modelsim/compile.do +++ b/hdl/fpga/platforms/bladerf/modelsim/compile.do @@ -10,6 +10,7 @@ vcom -work nuand -2008 ../../../ip/altera/rx_meta_fifo/rx_meta_fifo.vhd vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd +vcom -work nuand -2008 ../vhdl/fx3_gpif_p.vhd vcom -work nuand -2008 ../vhdl/fx3_gpif.vhd vcom -work nuand -2008 ../vhdl/bladerf.vhd From f3010f824923b7afb882e948c227cc64fcc6b645 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 12:06:06 -0500 Subject: [PATCH 11/41] hdl: test: variable gpif buf length support added to testbenches --- hdl/fpga/ip/nuand/simulation/sample_stream_tb.vhd | 5 +++-- .../bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd | 9 +++++---- .../bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd | 5 +++-- .../platforms/bladerf-micro/vhdl/tb/rx_timestamp_tb.vhd | 4 +++- .../platforms/bladerf-micro/vhdl/tb/wlan_fx3_model.vhd | 5 +++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/hdl/fpga/ip/nuand/simulation/sample_stream_tb.vhd b/hdl/fpga/ip/nuand/simulation/sample_stream_tb.vhd index 6952d26f..8d9876c9 100644 --- a/hdl/fpga/ip/nuand/simulation/sample_stream_tb.vhd +++ b/hdl/fpga/ip/nuand/simulation/sample_stream_tb.vhd @@ -28,6 +28,7 @@ library nuand ; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; library std ; use std.env.all ; @@ -435,8 +436,8 @@ begin wait until reset = '0' ; end if ; while true loop - wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > 512 ; - for i in 1 to 512 loop + wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > GPIF_BUF_SIZE_SS; + for i in 1 to GPIF_BUF_SIZE_SS loop rx_sample_fifo.rreq <= '1' ; nop( fx3_clock, 1 ) ; if( CHECK_OVERFLOW ) then diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd index e58db4f3..8b2d9447 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd @@ -32,6 +32,7 @@ library nuand; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; entity fx3_gpif_meta_8bit_tb is generic ( @@ -910,11 +911,11 @@ begin -- Allows a 0 increment for the first ts assertion if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1') then - ts_increment := 254 when EIGHT_BIT_MODE_EN = '0' - else 508; + ts_increment := (GPIF_BUF_SIZE_SS-4)/2 when EIGHT_BIT_MODE_EN = '0' + else (GPIF_BUF_SIZE_SS-4); else - ts_increment := 508 when EIGHT_BIT_MODE_EN = '0' - else 1016; + ts_increment := (GPIF_BUF_SIZE_SS -4) when EIGHT_BIT_MODE_EN = '0' + else 2*(GPIF_BUF_SIZE_SS -4); end if; iteration := iteration + 1; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd index 21e3618b..35bfec18 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd @@ -26,6 +26,7 @@ library ieee; library work; use work.util.all; + use work.fx3_gpif_p.all; architecture micro_dma_fifo_stress of fx3_model is @@ -98,7 +99,7 @@ begin done <= rx_done and tx_done; rx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable req_time : time; begin @@ -152,7 +153,7 @@ begin tx_sample_stream : process constant TIME_BETWEEN_ITERATIONS : natural := 4593; - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable timestamp_cntr : natural := 400; variable header_len : natural := 0; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/rx_timestamp_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/rx_timestamp_tb.vhd index 232d427a..704754dd 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/rx_timestamp_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/rx_timestamp_tb.vhd @@ -32,6 +32,7 @@ library nuand; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; entity rx_timestamp_tb is generic ( @@ -618,7 +619,8 @@ begin -- variable timestamp : unsigned(63 downto 0) := (others => '0'); begin wait for 1 ns; - delta_expected := to_unsigned(508, 64) when not EIGHT_BIT_MODE_EN else to_unsigned(1016, 64); + delta_expected := to_unsigned(GPIF_BUF_SIZE_SS-HEADER_LEN, 64) when not EIGHT_BIT_MODE_EN + else to_unsigned(2*(GPIF_BUF_SIZE_SS-HEADER_LEN), 64); if (ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1) then delta_expected := delta_expected/2; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/wlan_fx3_model.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/wlan_fx3_model.vhd index 2b80c591..eb9e69b7 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/wlan_fx3_model.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/wlan_fx3_model.vhd @@ -26,6 +26,7 @@ library ieee; library work; use work.util.all; + use work.fx3_gpif_p.all; architecture wlan_micro_packet_dma of fx3_model is @@ -108,7 +109,7 @@ begin done <= rx_done and tx_done; rx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable req_time : time; begin @@ -161,7 +162,7 @@ begin end process; tx_sample_stream : process - constant BLOCK_SIZE : natural := 512; + constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; variable timestamp_cntr : natural := 100; variable header_len : natural := 0; From af1b2ebc7a31c9d639522b5b310e848481b7b088 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 13:31:52 -0500 Subject: [PATCH 12/41] hdl: test: added variable gpif buffer length support for fx3_gpif_iq_tb --- hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_tb.vhd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_tb.vhd index 77dc714f..d0d24255 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_tb.vhd @@ -32,6 +32,7 @@ library nuand; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; entity fx3_gpif_iq_tb is generic ( @@ -638,6 +639,7 @@ begin look_for_dropped_tx_samples : process(tx_clock) is constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model variable current_message_count : natural := 1; + variable valid_sample_count : natural := 0; variable iq_value : signed (15 downto 0) := x"0000"; variable expected_sample_q : signed (15 downto 0); variable expected_sample_i : signed (15 downto 0); @@ -648,6 +650,7 @@ begin and dac_streams(i).data_v = '1' and fx3_control.tx_enable = '1' ) then + valid_sample_count := valid_sample_count + 1; expected_sample_i := iq_value; expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1); @@ -662,7 +665,7 @@ begin -- Set iq values based on blocks received -- See tx_sample_stream's encoding scheme in fx3_model.vhd - if( iq_value = x"03FE" ) then + if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then iq_value := x"0000"; if( current_message_count < MESSAGES_PER_ITERATION ) then current_message_count := current_message_count + 1; From 8f2280b7716cce7cc70225b94c4db8c33e383074 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 17:23:25 -0500 Subject: [PATCH 13/41] hdl: test: added variable gpif buffer length support for gpif meta tb --- .../platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_tb.vhd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_tb.vhd index c94cef1c..979c7e01 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_tb.vhd @@ -32,6 +32,7 @@ library nuand; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; entity fx3_gpif_meta_tb is generic ( @@ -683,8 +684,10 @@ begin end process tx_sample_start_check; look_for_dropped_tx_samples : process(tx_clock) is + constant HEADER_LEN : integer := 4; -- In clk cycles constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model variable current_message_count : natural := 1; + variable valid_sample_count : natural := 0; variable iq_value : signed (15 downto 0) := x"0000"; variable expected_sample_q : signed (15 downto 0); variable expected_sample_i : signed (15 downto 0); @@ -695,6 +698,7 @@ begin and dac_streams(i).data_v = '1' and fx3_control.tx_enable = '1' ) then + valid_sample_count := valid_sample_count + 1; expected_sample_i := iq_value; expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1); @@ -709,7 +713,7 @@ begin -- Set iq values based on blocks received -- See tx_sample_stream's encoding scheme in fx3_model.vhd - if( iq_value = x"03F6" ) then + if( valid_sample_count mod (GPIF_BUF_SIZE_SS-HEADER_LEN) = 0 ) then iq_value := x"0000"; if( current_message_count < MESSAGES_PER_ITERATION ) then current_message_count := current_message_count + 1; From 0da168b8231b0abb99ee4c0105a7bde577691feb Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 17:18:56 -0500 Subject: [PATCH 14/41] hdl: test: added variable gpif buffer length support for 8b testbenches --- .../vhdl/tb/fx3_gpif_iq_8bit_tb.vhd | 5 ++++- .../vhdl/tb/fx3_gpif_meta_8bit_tb.vhd | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_tb.vhd index a39550ac..dd22b9d2 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_tb.vhd @@ -32,6 +32,7 @@ library nuand; use nuand.fifo_readwrite_p.all; use nuand.common_dcfifo_p.all; use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; entity fx3_gpif_iq_8bit_tb is generic ( @@ -659,6 +660,7 @@ begin constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000"; variable current_message_count : natural := 1; + variable valid_sample_count : natural := 0; variable iq_value : signed (15 downto 0) := x"0000"; variable expected_sample_i : signed (15 downto 0); variable expected_sample_q : signed (15 downto 0); @@ -670,6 +672,7 @@ begin and dac_streams(i).data_v = '1' and fx3_control.tx_enable = '1' ) then + valid_sample_count := valid_sample_count + 1; if( EIGHT_BIT_MODE_EN = '1' ) then expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS; expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS; @@ -706,7 +709,7 @@ begin -- Set iq values based on blocks received -- See tx_sample_stream's encoding scheme in fx3_model.vhd - if( iq_value = x"03FE" ) then + if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then iq_value := x"0000"; if( current_message_count < MESSAGES_PER_ITERATION ) then current_message_count := current_message_count + 1; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd index 8b2d9447..2fca50a3 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_meta_8bit_tb.vhd @@ -697,7 +697,8 @@ begin look_for_dropped_tx_samples : process(tx_clock) is constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000"; - variable dac_stream_back_to_0 : natural := 0; + constant HEADER_LEN : natural := 4; -- In clk cycles + variable valid_sample_count : natural := 0; variable current_message_count : natural := 1; variable iq_value : signed (15 downto 0) := x"0000"; variable expected_sample_i : signed (15 downto 0); @@ -710,6 +711,7 @@ begin and dac_streams(i).data_v = '1' and fx3_control.tx_enable = '1' ) then + valid_sample_count := valid_sample_count + 1; if( EIGHT_BIT_MODE_EN = '1' ) then expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS; expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS; @@ -730,9 +732,16 @@ begin end if; end if; - dac_stream_back_to_0 := dac_stream_back_to_0 + 1 when iq_value = 0; - iq_value := (iq_value + 2) mod 128 when dac_stream_back_to_0 mod 16 /= 0 else - (iq_value + 2) mod 112; + if( valid_sample_count mod (2*GPIF_BUF_SIZE_SS - 8) = 0 ) then + iq_value := x"0000"; + if( current_message_count < MESSAGES_PER_ITERATION ) then + current_message_count := current_message_count + 1; + else + current_message_count := 1; + end if; + else + iq_value := (iq_value + 2) mod 128; + end if; else expected_sample_i := iq_value; expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1); @@ -748,7 +757,7 @@ begin -- Set iq values based on blocks received -- See tx_sample_stream's encoding scheme in fx3_model.vhd - if( iq_value = x"03F6" ) then + if( valid_sample_count mod (GPIF_BUF_SIZE_SS - HEADER_LEN) = 0 ) then iq_value := x"0000"; if( current_message_count < MESSAGES_PER_ITERATION ) then current_message_count := current_message_count + 1; From b0ed92eae8efe67c416adc8f3376068f0ff373f2 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 29 Jul 2024 14:23:05 -0500 Subject: [PATCH 15/41] fx3_firmware: increase DMA buffer sizes for USB throughput bottleneck $ make test_hdl [----------] Global test environment tear-down [==========] 63 tests from 2 test suites ran. (381209 ms total) [ PASSED ] 63 tests. [100%] Built target test_hdl --- fx3_firmware/src/rf.c | 4 ++-- hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd | 4 ++-- host/libraries/libbladeRF/src/backend/usb/usb.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fx3_firmware/src/rf.c b/fx3_firmware/src/rf.c index ba992402..a50a9f56 100644 --- a/fx3_firmware/src/rf.c +++ b/fx3_firmware/src/rf.c @@ -290,8 +290,8 @@ static void NuandRFLinkStart(void) } CyU3PMemSet((uint8_t *)&dmaCfg, 0, sizeof(dmaCfg)); - dmaCfg.size = size * 2; - dmaCfg.count = 22; + dmaCfg.size = size * 8; + dmaCfg.count = 11; dmaCfg.prodSckId = BLADE_RF_SAMPLE_EP_PRODUCER_USB_SOCKET; dmaCfg.consSckId = CY_U3P_PIB_SOCKET_3; dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE; diff --git a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd index 43d7673c..f9c64182 100644 --- a/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd +++ b/hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd @@ -22,6 +22,6 @@ use ieee.std_logic_1164.all; package fx3_gpif_p is -- GPIF buf sizes for USB high-speed and super-speed - constant GPIF_BUF_SIZE_HS : natural := 256; - constant GPIF_BUF_SIZE_SS : natural := 512; + constant GPIF_BUF_SIZE_HS : natural := 1024; + constant GPIF_BUF_SIZE_SS : natural := 2048; end package fx3_gpif_p; diff --git a/host/libraries/libbladeRF/src/backend/usb/usb.h b/host/libraries/libbladeRF/src/backend/usb/usb.h index 644ed7a3..80e9b7a3 100644 --- a/host/libraries/libbladeRF/src/backend/usb/usb.h +++ b/host/libraries/libbladeRF/src/backend/usb/usb.h @@ -61,8 +61,8 @@ extern bool bladerf_usb_reset_device_on_open; #endif /* Size of a host<->FPGA message in BYTES */ -#define USB_MSG_SIZE_SS 2048 -#define USB_MSG_SIZE_HS 1024 +#define USB_MSG_SIZE_SS 8192 +#define USB_MSG_SIZE_HS 4096 typedef enum { USB_TARGET_DEVICE, From e6bbdd69cc3fdd2b98f599022de0ab62f3e5f539 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 27 Feb 2025 17:36:03 -0600 Subject: [PATCH 16/41] libbladeRF: support and clamp byte alignment to larger GPIF buffer size This change also includes a refactor of the redundant format to sample size conversions found within the synchronous and asynchronous interfaces. --- .../libraries/libbladeRF/include/libbladeRF.h | 2 +- .../libbladeRF/src/streaming/async.c | 26 +++------------ .../libbladeRF/src/streaming/metadata.h | 2 +- .../libraries/libbladeRF/src/streaming/sync.c | 33 +++++++++---------- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 0e0a922d..7c331dcc 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -2731,7 +2731,7 @@ int CALL_CONV bladerf_get_timestamp(struct bladerf *dev, * data stream. This must be greater than the * `num_xfers` parameter. * @param[in] buffer_size The size of the underlying stream buffers, in - * samples. This value must be a multiple of 1024. + * samples. This value must be a multiple of 2048. * Note that samples are only transferred when a * buffer of this size is filled. * @param[in] num_transfers The number of active USB transfers that may be diff --git a/host/libraries/libbladeRF/src/streaming/async.c b/host/libraries/libbladeRF/src/streaming/async.c index cffa9d21..1eee58d4 100644 --- a/host/libraries/libbladeRF/src/streaming/async.c +++ b/host/libraries/libbladeRF/src/streaming/async.c @@ -52,8 +52,10 @@ int async_init_stream(struct bladerf_stream **stream, return BLADERF_ERR_INVAL; } - if (samples_per_buffer < 1024 || samples_per_buffer % 1024 != 0) { - log_error("samples_per_buffer must be multiples of 1024\n"); + buffer_size_bytes = samples_to_bytes(format, samples_per_buffer); + if (buffer_size_bytes < USB_MSG_SIZE_SS || buffer_size_bytes % USB_MSG_SIZE_SS != 0) { + log_error("Samples_per_buffer must be multiples of %u\n", + bytes_to_samples(format, USB_MSG_SIZE_SS)); return BLADERF_ERR_INVAL; } @@ -109,26 +111,6 @@ int async_init_stream(struct bladerf_stream **stream, } } - switch(format) { - case BLADERF_FORMAT_SC8_Q7: - case BLADERF_FORMAT_SC8_Q7_META: - buffer_size_bytes = sc8q7_to_bytes(samples_per_buffer); - break; - - case BLADERF_FORMAT_SC16_Q11: - case BLADERF_FORMAT_SC16_Q11_META: - buffer_size_bytes = sc16q11_to_bytes(samples_per_buffer); - break; - - case BLADERF_FORMAT_PACKET_META: - buffer_size_bytes = samples_per_buffer; - break; - - default: - status = BLADERF_ERR_INVAL; - break; - } - if (!status) { lstream->buffers = calloc(num_buffers, sizeof(lstream->buffers[0])); if (lstream->buffers) { diff --git a/host/libraries/libbladeRF/src/streaming/metadata.h b/host/libraries/libbladeRF/src/streaming/metadata.h index e2685596..55f6a594 100644 --- a/host/libraries/libbladeRF/src/streaming/metadata.h +++ b/host/libraries/libbladeRF/src/streaming/metadata.h @@ -24,7 +24,7 @@ * ~~~~~~~~~~~~~~~~~~~~~~~ * * The FPGA handles data in units of "messages." These messages are - * 1024 or 2048 bytes for USB 2.0 (Hi-Speed) or USB 3.0 (SuperSpeed), + * 2048 or 8192 bytes for USB 2.0 (Hi-Speed) or USB 3.0 (SuperSpeed), * respectively. * * The first 16 bytes of the message form a header, which includes metadata diff --git a/host/libraries/libbladeRF/src/streaming/sync.c b/host/libraries/libbladeRF/src/streaming/sync.c index feef101b..600dde8f 100644 --- a/host/libraries/libbladeRF/src/streaming/sync.c +++ b/host/libraries/libbladeRF/src/streaming/sync.c @@ -141,6 +141,8 @@ int sync_init(struct bladerf_sync *sync, { int status = 0; size_t i, bytes_per_sample; + size_t bytes_per_buffer; + const size_t GPIF_BUF_SIZE = 8192; if (num_transfers >= num_buffers) { return BLADERF_ERR_INVAL; @@ -168,27 +170,22 @@ int sync_init(struct bladerf_sync *sync, } } - switch (format) { - case BLADERF_FORMAT_SC8_Q7: - case BLADERF_FORMAT_SC8_Q7_META: - bytes_per_sample = 2; - break; + bytes_per_sample = samples_to_bytes(format, 1); + bytes_per_buffer = samples_to_bytes(format, buffer_size); + if (bytes_per_buffer < GPIF_BUF_SIZE || bytes_per_buffer % GPIF_BUF_SIZE != 0) { + size_t original_size = buffer_size; - case BLADERF_FORMAT_SC16_Q11: - case BLADERF_FORMAT_SC16_Q11_META: - case BLADERF_FORMAT_PACKET_META: - bytes_per_sample = 4; - break; + /* Round up to the next multiple of GPIF_BUF_SIZE, ensuring at least one GPIF buffer */ + buffer_size = bytes_per_buffer == 0 ? GPIF_BUF_SIZE / bytes_per_sample : + ((bytes_per_buffer + GPIF_BUF_SIZE - 1) / GPIF_BUF_SIZE) + * (GPIF_BUF_SIZE / bytes_per_sample); - default: - log_debug("Invalid format value: %d\n", format); - return BLADERF_ERR_INVAL; - } + log_warning("Requested buffer size %zu samples (%zu bytes) is invalid. " + "Adjusting to %zu samples (%zu bytes).\n", + original_size, samples_to_bytes(format, original_size), + buffer_size, samples_to_bytes(format, buffer_size)); - /* bladeRF GPIF DMA requirement */ - if ((bytes_per_sample * buffer_size) % 4096 != 0) { - assert(!"Invalid buffer size"); - return BLADERF_ERR_INVAL; + bytes_per_buffer = samples_to_bytes(format, buffer_size); } /* Deinitialize sync handle if it's initialized */ From 71f9cd4e9f019cf0532bb2156262e409d12353c2 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 17:39:42 -0500 Subject: [PATCH 17/41] doc: updated buf size limit in examples and tests --- host/libraries/libbladeRF/doc/examples/sync_rx_meta.c | 2 +- host/libraries/libbladeRF/doc/examples/sync_rxtx.c | 2 +- host/libraries/libbladeRF/doc/examples/sync_tx_meta.c | 2 +- host/libraries/libbladeRF_test/test_rx_meta/src/main.c | 2 +- host/libraries/libbladeRF_test/test_streaming/src/main.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/host/libraries/libbladeRF/doc/examples/sync_rx_meta.c b/host/libraries/libbladeRF/doc/examples/sync_rx_meta.c index 40081124..1799a257 100644 --- a/host/libraries/libbladeRF/doc/examples/sync_rx_meta.c +++ b/host/libraries/libbladeRF/doc/examples/sync_rx_meta.c @@ -57,7 +57,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples, bladerf_format format, * restricted to multiples of any particular size. * * The value for `num_samples` has no major restrictions here, while the - * `buffer_size` below must be a multiple of 1024. + * `buffer_size` below must be a multiple of 2048. */ int16_t *samples; diff --git a/host/libraries/libbladeRF/doc/examples/sync_rxtx.c b/host/libraries/libbladeRF/doc/examples/sync_rxtx.c index 69b65f81..c92a6ff1 100644 --- a/host/libraries/libbladeRF/doc/examples/sync_rxtx.c +++ b/host/libraries/libbladeRF/doc/examples/sync_rxtx.c @@ -67,7 +67,7 @@ static int init_sync(struct bladerf *dev) * received. */ const unsigned int num_buffers = 16; - const unsigned int buffer_size = 8192; /* Must be a multiple of 1024 */ + const unsigned int buffer_size = 8192; /* Must be a multiple of 2048 */ const unsigned int num_transfers = 8; const unsigned int timeout_ms = 3500; diff --git a/host/libraries/libbladeRF/doc/examples/sync_tx_meta.c b/host/libraries/libbladeRF/doc/examples/sync_tx_meta.c index 6a15db56..19b59252 100644 --- a/host/libraries/libbladeRF/doc/examples/sync_tx_meta.c +++ b/host/libraries/libbladeRF/doc/examples/sync_tx_meta.c @@ -94,7 +94,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples) * restricted to multiples of any particular size. * * The value for `num_samples` has no major restrictions here, while the - * `buffer_size` below must be a multiple of 1024. + * `buffer_size` below must be a multiple of 2048. */ int16_t *samples; diff --git a/host/libraries/libbladeRF_test/test_rx_meta/src/main.c b/host/libraries/libbladeRF_test/test_rx_meta/src/main.c index 629c1921..f7238773 100644 --- a/host/libraries/libbladeRF_test/test_rx_meta/src/main.c +++ b/host/libraries/libbladeRF_test/test_rx_meta/src/main.c @@ -57,7 +57,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples, bladerf_format format, * restricted to multiples of any particular size. * * The value for `num_samples` has no major restrictions here, while the - * `buffer_size` below must be a multiple of 1024. + * `buffer_size` below must be a multiple of 2048. */ int16_t *samples; diff --git a/host/libraries/libbladeRF_test/test_streaming/src/main.c b/host/libraries/libbladeRF_test/test_streaming/src/main.c index e92c17f5..76f598de 100644 --- a/host/libraries/libbladeRF_test/test_streaming/src/main.c +++ b/host/libraries/libbladeRF_test/test_streaming/src/main.c @@ -90,7 +90,7 @@ void print_help() { printf(" -e, --meta Enable META test\n"); printf(" -s, --samplerate Specify the sample rate\n"); printf(" -n, --num-samples Specify the number of samples\n"); - printf(" -b, --buffer-size Specify the buffer size (multiple of 1024)\n"); + printf(" -b, --buffer-size Specify the buffer size (multiple of 2048)\n"); printf(" -h, --help Display this help message\n"); printf("\n"); From 2c2c4c1505a97f7c88c3f0eef14a41613f4c8645 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 30 Jul 2024 17:53:13 -0500 Subject: [PATCH 18/41] doc: bladeRF-cli: updated sample limit to match buffer limit --- .../utilities/bladeRF-cli/src/cmd/doc/interactive-help.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/host/utilities/bladeRF-cli/src/cmd/doc/interactive-help.md b/host/utilities/bladeRF-cli/src/cmd/doc/interactive-help.md index d1ce8758..abeb1319 100644 --- a/host/utilities/bladeRF-cli/src/cmd/doc/interactive-help.md +++ b/host/utilities/bladeRF-cli/src/cmd/doc/interactive-help.md @@ -746,8 +746,8 @@ available parameters. `bitmode` state `samples` Number of samples per buffer to use in the - asynchronous stream. Must be divisible by 1024 and - >= 1024. + asynchronous stream. Must be divisible by 2048 and + >= 2048. `buffers` Number of sample buffers to use in the asynchronous stream. The min value is 4. @@ -935,8 +935,8 @@ available parameters. retransmitting file contents. 0 implies no delay. `samples` Number of samples per buffer to use in the - asynchronous stream. Must be divisible by 1024 and - >= 1024. + asynchronous stream. Must be divisible by 2048 and + >= 2048. `buffers` Number of sample buffers to use in the asynchronous stream. The min value is 4. From 350ebbee433bd5cc9fbfdaef46ef45e1bd6d86e2 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 31 Jul 2024 15:44:28 -0500 Subject: [PATCH 19/41] hdl: revert jtag timing fixes SignalTap may throw a "jtag instance not found" error which is sourced from not meeting timing requirements for the jtag interface. Reverting previous fixes may resurface some timing issues, but the "instance not found" error at least goes away and I can use signal tap again. Sources: SignalTap-II -> "instance not found" error https://community.intel.com/t5/Programmable-Devices/SignalTap-II-gt-quot-instance-not-found-quot-error/m-p/238886 How to set timing constraint for JTAG https://community.intel.com/t5/Programmable-Devices/How-to-set-timing-constraint-for-JTAG/m-p/1379278 --- hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc b/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc index 41b5ca59..85b16c3e 100644 --- a/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc +++ b/hdl/fpga/platforms/bladerf-micro/constraints/bladerf.sdc @@ -71,11 +71,10 @@ set_false_path -from exp_present -to * set_false_path -from pwr_status -to * # JTAG settings -create_clock -name {altera_reserved_tck} -period 100 [get_ports {altera_reserved_tck}] -set_clock_groups -asynchronous -group {altera_reserved_tck} -set_false_path -from [get_ports {altera_reserved_tms}] -set_false_path -from [get_ports {altera_reserved_tdi}] -set_false_path -to [get_ports {altera_reserved_tdo}] +set_clock_groups -exclusive -group [get_clocks altera_reserved_tck] +set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdi] +set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tms] +set_output_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdo] # Exceptions From 5ba9b6d916114ed14347eeb8a5318d1b546d63fc Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Fri, 26 Jul 2024 17:29:48 -0500 Subject: [PATCH 20/41] fx3_firmware: rev libbladeRF, hdl, and fx3 for 2048 sample gpif buffers FX3 GPIF buffers set to 2048 samples and number of buffers reduced to 11 per dma channel. This substantially increases the theoretical USB SuperSpeed throughput from roughly 228MB/s to 356MB/s. $ make test_libbladeRF [ OK ] libbladeRF.scheduled_retune (19755 ms) [----------] 29 tests from libbladeRF (308802 ms total) [----------] Global test environment tear-down [==========] 29 tests from 1 test suite ran. (308802 ms total) [ PASSED ] 29 tests. --- fx3_firmware/CHANGELOG | 5 +++++ fx3_firmware/CMakeLists.txt | 2 +- .../bladerf-micro/software/bladeRF_nios/src/fpga_version.h | 4 ++-- host/libraries/libbladeRF/CMakeLists.txt | 4 ++-- host/libraries/libbladeRF/include/libbladeRF.h | 2 +- host/libraries/libbladeRF/src/board/bladerf2/compatibility.c | 2 ++ 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fx3_firmware/CHANGELOG b/fx3_firmware/CHANGELOG index 6b3580dc..63480bd3 100644 --- a/fx3_firmware/CHANGELOG +++ b/fx3_firmware/CHANGELOG @@ -6,6 +6,11 @@ hosted on GitHub: https://github.com/nuand/bladeRF ================================================================================ +v2.5.0 (2024-07-30) +-------------------------------- + * Bumped GPIF DMA buffer size to 8192 bytes + * Reduced the number of GPIF DMA buffers to 11 per channel + v2.4.0 (2020-08-01) -------------------------------- * Add ability to send short packets to FX3 from FPGA diff --git a/fx3_firmware/CMakeLists.txt b/fx3_firmware/CMakeLists.txt index e2985177..fcd98074 100644 --- a/fx3_firmware/CMakeLists.txt +++ b/fx3_firmware/CMakeLists.txt @@ -33,7 +33,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../host/cmake/modules) # Update these definitions when updating the firmware version set(VERSION_INFO_MAJOR 2) -set(VERSION_INFO_MINOR 4) +set(VERSION_INFO_MINOR 5) set(VERSION_INFO_PATCH 0) if(NOT DEFINED VERSION_INFO_EXTRA) diff --git a/hdl/fpga/platforms/bladerf-micro/software/bladeRF_nios/src/fpga_version.h b/hdl/fpga/platforms/bladerf-micro/software/bladeRF_nios/src/fpga_version.h index d66033f5..8b1a4cd8 100644 --- a/hdl/fpga/platforms/bladerf-micro/software/bladeRF_nios/src/fpga_version.h +++ b/hdl/fpga/platforms/bladerf-micro/software/bladeRF_nios/src/fpga_version.h @@ -7,8 +7,8 @@ #define FPGA_VERSION_ID 0x7777 #define FPGA_VERSION_MAJOR 0 -#define FPGA_VERSION_MINOR 15 -#define FPGA_VERSION_PATCH 3 +#define FPGA_VERSION_MINOR 16 +#define FPGA_VERSION_PATCH 0 #define FPGA_VERSION ((uint32_t)( FPGA_VERSION_MAJOR | \ (FPGA_VERSION_MINOR << 8) | \ (FPGA_VERSION_PATCH << 16) ) ) diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index 5f0ebd90..f1074908 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -7,8 +7,8 @@ project(libbladeRF C) ################################################################################ set(VERSION_INFO_MAJOR 2) -set(VERSION_INFO_MINOR 5) -set(VERSION_INFO_PATCH 1) +set(VERSION_INFO_MINOR 6) +set(VERSION_INFO_PATCH 0) set(LIBBLADERF_VERSION ${VERSION_INFO_MAJOR}.${VERSION_INFO_MINOR}.${VERSION_INFO_PATCH}) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 7c331dcc..4b5f1ece 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -51,7 +51,7 @@ * * https://github.com/Nuand/bladeRF/blob/master/doc/development/versioning.md */ -#define LIBBLADERF_API_VERSION (0x02050100) +#define LIBBLADERF_API_VERSION (0x02060000) #ifdef __cplusplus extern "C" { diff --git a/host/libraries/libbladeRF/src/board/bladerf2/compatibility.c b/host/libraries/libbladeRF/src/board/bladerf2/compatibility.c index 7ee0b8e0..8801d174 100644 --- a/host/libraries/libbladeRF/src/board/bladerf2/compatibility.c +++ b/host/libraries/libbladeRF/src/board/bladerf2/compatibility.c @@ -13,6 +13,7 @@ static const struct compat fw_compat[] = { /* Firmware requires >= FPGA */ + { VERSION(2, 5, 0), VERSION(0, 16, 0) }, { VERSION(2, 4, 0), VERSION(0, 6, 0) }, { VERSION(2, 3, 2), VERSION(0, 6, 0) }, { VERSION(2, 3, 1), VERSION(0, 6, 0) }, @@ -27,6 +28,7 @@ const struct version_compat_table bladerf2_fw_compat_table = {fw_compat, ARRAY_S static const struct compat fpga_compat[] = { /* FPGA requires >= Firmware */ + { VERSION(0, 16, 0), VERSION(2, 5, 0) }, { VERSION(0, 15, 3), VERSION(2, 4, 0) }, { VERSION(0, 15, 2), VERSION(2, 4, 0) }, { VERSION(0, 15, 1), VERSION(2, 4, 0) }, From 2e710ea63431192994aa49283df7decbeb580f60 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Fri, 27 Sep 2024 15:43:02 -0500 Subject: [PATCH 21/41] doc: updated fx3 firmware folder name --- fx3_firmware/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fx3_firmware/README.md b/fx3_firmware/README.md index bf7e43fa..195dad6f 100644 --- a/fx3_firmware/README.md +++ b/fx3_firmware/README.md @@ -38,7 +38,7 @@ Adjust the paths as necessary on your system, depending where you installed the ``` $ mkdir build $ cd build -$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_sdk -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../ +$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_firmware_linux -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../ $ make ``` From cb8a2e574b62bc22f0efc89de438ce42baccf2b0 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 29 Feb 2024 17:13:00 -0600 Subject: [PATCH 22/41] libbladeRF: test: added packet test --- host/libraries/libbladeRF_test/CMakeLists.txt | 1 + .../test_packet/CMakeLists.txt | 31 +++ .../libbladeRF_test/test_packet/src/main.c | 207 ++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 host/libraries/libbladeRF_test/test_packet/CMakeLists.txt create mode 100644 host/libraries/libbladeRF_test/test_packet/src/main.c diff --git a/host/libraries/libbladeRF_test/CMakeLists.txt b/host/libraries/libbladeRF_test/CMakeLists.txt index 00fc3efe..e637ca8a 100644 --- a/host/libraries/libbladeRF_test/CMakeLists.txt +++ b/host/libraries/libbladeRF_test/CMakeLists.txt @@ -10,6 +10,7 @@ add_subdirectory(test_ctrl) add_subdirectory(test_freq_hop) add_subdirectory(test_fw_check) add_subdirectory(test_open) +add_subdirectory(test_packet) add_subdirectory(test_parse) add_subdirectory(test_peripheral_timing) add_subdirectory(test_gain_compare) diff --git a/host/libraries/libbladeRF_test/test_packet/CMakeLists.txt b/host/libraries/libbladeRF_test/test_packet/CMakeLists.txt new file mode 100644 index 00000000..69f3c46a --- /dev/null +++ b/host/libraries/libbladeRF_test/test_packet/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.5) +project(libbladeRF_test_packet C) + +set(INCLUDES + ${CMAKE_CURRENT_SOURCE_DIR}/../common/include + ${libbladeRF_SOURCE_DIR}/include + ${BLADERF_HOST_COMMON_INCLUDE_DIRS} +) + +# Checks if the include directories exist +foreach(dir ${INCLUDES}) + if(NOT EXISTS ${dir}) + message(FATAL_ERROR "The include directory '${dir}' does not exist.") + endif() +endforeach() + +set(SRC + src/main.c + ${BLADERF_HOST_COMMON_SOURCE_DIR}/log.c + ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c) + +if(MSVC) + set(SRC ${SRC} + ${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c + ) +endif() + +include_directories(${INCLUDES}) +add_executable(${PROJECT_NAME} ${SRC}) +target_link_libraries(${PROJECT_NAME} libbladerf_shared) + diff --git a/host/libraries/libbladeRF_test/test_packet/src/main.c b/host/libraries/libbladeRF_test/test_packet/src/main.c new file mode 100644 index 00000000..5e0dd975 --- /dev/null +++ b/host/libraries/libbladeRF_test/test_packet/src/main.c @@ -0,0 +1,207 @@ +#include +#include +#include "test_common.h" +#include "libbladeRF.h" +#include "log.h" +#include "conversions.h" + +#define dword_t int32_t +#define DYNAMIC_PACKET_LEN 0 + +typedef struct test { + bladerf_frequency frequency; + bladerf_sample_rate samplerate; + bladerf_bandwidth bandwidth; + + // Sync interface + bladerf_channel channel; + uint32_t num_buffers; + uint32_t buffer_len; + + // Packets + size_t num_dwords; + size_t num_packets; +} test_t; + +void test_config_init(test_t *t) { + t->frequency = 915e6; + t->samplerate = 10e6; + t->bandwidth = 10e6; + + t->channel = BLADERF_CHANNEL_TX(0); + t->num_buffers = 512; + t->buffer_len = 4096; + + t->num_dwords = DYNAMIC_PACKET_LEN; + t->num_packets = 10; +} + +int bladerf_config(struct bladerf *dev, const test_t *test) { + int status = 0; + CHECK_NULL(dev, test); + + CHECK_STATUS(bladerf_set_frequency(dev, test->channel, test->frequency)); + CHECK_STATUS(bladerf_set_sample_rate(dev, test->channel, test->samplerate, NULL)); + CHECK_STATUS(bladerf_set_bandwidth(dev, test->channel, test->bandwidth, NULL)); + CHECK_STATUS(bladerf_sync_config(dev, test->channel, BLADERF_FORMAT_PACKET_META, + test->num_buffers, test->buffer_len, 16, 3e6)); + +error: + return status; +} + +int send_packets_variable_len(struct bladerf *dev, const test_t *test) { + CHECK_NULL(dev, test); + int status = 0; + struct bladerf_metadata meta; + + size_t dynamic_packet_len = 0; + size_t packet_sizes[4] = {40, 17, 43, dynamic_packet_len}; + + memset(&meta, 0, sizeof(meta)); + meta.flags = BLADERF_META_FLAG_TX_BURST_START | BLADERF_META_FLAG_TX_NOW | BLADERF_META_FLAG_TX_BURST_END; + + CHECK_STATUS(bladerf_enable_module(dev, test->channel, true)); + + size_t packet_idx = 0; + for (size_t i = 0; i < test->num_packets; i++) { + dynamic_packet_len = 20 + (i % 300); + packet_sizes[3] = dynamic_packet_len; + + size_t current_packet_len = packet_sizes[packet_idx % 4]; // Select packet size in round-robin fashion + size_t packet_size = current_packet_len * sizeof(dword_t); + dword_t *packet = malloc(packet_size); + CHECK_NULL(packet); + + for (size_t j = 0; j < current_packet_len; j++) { + packet[j] = j; + } + + CHECK_STATUS(bladerf_sync_tx(dev, packet, bytes_to_dwords(packet_size), &meta, 3e3)); + + free(packet); + packet_idx++; // Move to the next packet size for the next iteration + } + + CHECK_STATUS(bladerf_enable_module(dev, test->channel, false)); + +error: + return status; +} + +int send_packets_static_len(struct bladerf *dev, const test_t *test) { + int status = 0; + struct bladerf_metadata meta; + CHECK_NULL(dev); + + size_t packets_size = test->num_dwords * sizeof(dword_t); + dword_t *packet = malloc(packets_size); + CHECK_NULL(packet); + + for (size_t i = 0; i < test->num_dwords; i++) { + packet[i] = i; + } + + memset(&meta, 0, sizeof(meta)); + meta.flags = BLADERF_META_FLAG_TX_BURST_START | BLADERF_META_FLAG_TX_NOW | + BLADERF_META_FLAG_TX_BURST_END; + + CHECK_STATUS(bladerf_enable_module(dev, test->channel, true)); + + for (size_t i = 0; i < test->num_packets; i++) { + CHECK_STATUS(bladerf_sync_tx(dev, packet, bytes_to_dwords(packets_size), &meta, 3e3)); + } + + CHECK_STATUS(bladerf_enable_module(dev, test->channel, false)); + +error: + free(packet); + return status; +} + +static const struct option long_options[] = { + { "packets", required_argument, NULL, 'n' }, + { "size", required_argument, NULL, 's' }, + { "device", required_argument, NULL, 'd' }, + { "verbosity", required_argument, NULL, 'v' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 }, +}; + +int main(int argc, char *argv[]) +{ + int status = 0; + int opt = 0; + int opt_ind = 0; + bool ok; + struct bladerf *dev; + char *devstr = NULL; + test_t test; + bladerf_log_level log_level; + + test_config_init(&test); + + while ((opt = getopt_long(argc, argv, "n:s:d:v:h", long_options, &opt_ind)) != -1) { + switch (opt) { + case 'n': + test.num_packets = strtoul(optarg, NULL, 0); + break; + + case 's': + test.num_dwords = strtoul(optarg, NULL, 0); + break; + + case 'd': + devstr = optarg; + break; + + case 'v': + log_level = str2loglevel(optarg, &ok); + if (!ok) { + fprintf(stderr, "Invalid log level: %s\n", optarg); + return -1; + } + bladerf_log_set_verbosity(log_level); + break; + + case 'h': + printf("Usage: %s [options]\n", argv[0]); + printf("Options:\n"); + printf(" -n, --packets Number of packets to send.\n"); + printf(" -s, --size Number of dwords per packet.\n"); + printf(" -d, --device Specify the device to open. Allows selection of a specific\n"); + printf(" bladeRF device if multiple are available.\n"); + printf(" -v, --verbosity Set libbladeRF verbosity level.\n"); + printf(" -h, --help Show this help message and exit.\n"); + printf("\n"); + printf("The program transmits packets using the bladeRF library. If '--size 0' is used, packets\n"); + printf("will be sent with variable lengths in a round-robin fashion: 40, 17, 43 dwords, and\n"); + printf("a dynamic packet length of '20 + (packet_count %% 300)'. Otherwise, all packets\n"); + printf("will have a static length as specified by '--size'.\n"); + return 0; + + default: + return EXIT_FAILURE; + } + } + + printf("Opening device: %s\n", (devstr == NULL) ? "any" : devstr); + CHECK_STATUS(bladerf_open(&dev, devstr)); + CHECK_STATUS(bladerf_config(dev, &test)); + + if (test.num_dwords == DYNAMIC_PACKET_LEN) { + printf("Sending %zu packets with the following packet length and order:\n", test.num_packets); + printf("Packet Lengths: [%i, %i, %i, 20 + (packets_sent %% 300)] dwords\n", 40, 17, 43); + + CHECK_STATUS(send_packets_variable_len(dev, &test)); + } else { + printf("Sending %zu packets: %zu dwords/packet (%zu bytes/packet)\n", + test.num_packets, test.num_dwords, test.num_dwords * sizeof(dword_t)); + + CHECK_STATUS(send_packets_static_len(dev, &test)); + } + +error: + bladerf_close(dev); + return (status == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} From caf37834ee187343f34cea067a64eb457178c7fd Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 27 Feb 2025 18:14:18 -0600 Subject: [PATCH 23/41] hdl: added enable signal for highly packed mode --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 1 + hdl/fpga/platforms/bladerf-micro/vhdl/rx.vhd | 2 ++ hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd | 1 + 3 files changed, 4 insertions(+) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index 36fa0098..d0ed1419 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -43,6 +43,7 @@ entity fifo_writer is meta_en : in std_logic; packet_en : in std_logic; eight_bit_mode_en : in std_logic := '0'; + highly_packed_mode_en : in std_logic; timestamp : in unsigned(63 downto 0); mini_exp : in std_logic_vector(1 downto 0); diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/rx.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/rx.vhd index a2e22c12..5ff34e3f 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/rx.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/rx.vhd @@ -51,6 +51,7 @@ entity rx is -- 8-bit mode eight_bit_mode_en : in std_logic := '0'; + highly_packed_mode_en : in std_logic := '0'; -- Packet to host via FX3 packet_en : in std_logic; @@ -251,6 +252,7 @@ begin packet_ready => packet_ready, eight_bit_mode_en => eight_bit_mode_en, + highly_packed_mode_en => highly_packed_mode_en, meta_fifo_full => meta_fifo.wfull, meta_fifo_usedw => meta_fifo.wused, diff --git a/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd b/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd index a0f7db0d..504750e8 100644 --- a/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd +++ b/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd @@ -769,6 +769,7 @@ begin meta_en => meta_en_rx, packet_en => packet_en_rx, eight_bit_mode_en => '0', + highly_packed_mode_en => '0', timestamp => rx_timestamp, mini_exp => mini_exp2 & mini_exp1, From 2c85c7be36aa615b869ab1c1210c6f4d054e3683 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 27 Feb 2025 12:51:23 -0600 Subject: [PATCH 24/41] hdl: added highly packed mode to fifo writer Iteratively packs 12b'samples across 3 fifo writes. The meta downcount operation still needs to be confirmed. --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 93 +++++++++++++++++++-- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index d0ed1419..43c52790 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -120,6 +120,8 @@ architecture simple of fifo_writer is fifo_clear : std_logic; fifo_write : std_logic; fifo_data : unsigned(fifo_data'range); + fifo_12b_buf : unsigned(95 downto 0); + write_cycle : natural range 0 to 3; samples_left : natural range 0 to in_sample_controls'length; in_sample_controls_r: sample_controls_t(0 to NUM_STREAMS-1); in_samples_r : sample_streams_t(0 to NUM_STREAMS-1); @@ -131,6 +133,8 @@ architecture simple of fifo_writer is fifo_clear => '1', fifo_write => '0', fifo_data => (others => '-'), + fifo_12b_buf => (others => '-'), + write_cycle => 0, samples_left => 0, in_sample_controls_r=> (others => SAMPLE_CONTROL_DISABLE), in_samples_r => (others => ZERO_SAMPLE), @@ -432,6 +436,57 @@ begin return rv; end function; + + -- -------------------------------------------------------------------- + -- MIMO PACKER: STEP 1 of 3 (SC12Q11 Highly Packed Mode) + -- -------------------------------------------------------------------- + -- This block receives samples as an array of sample streams, one + -- element per channel. These streams need to be packed into a single, + -- wide bus that is written to a FIFO and delivered to the host. + -- For SC12Q11 (SC16_Q11_PACKED) format, each I and Q sample is 12 bits wide. + -- + -- This packing scheme efficiently utilizes the available bandwidth + -- for the SC12Q11 format, allowing for 8 complete IQ pairs every 3 cycles. + -- + -- The packing process fills 3 cycles of a 64-bit buffer with 8 24b IQ pairs: + -- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices + -- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples + -- [-----][--------full 12-bit samples-----------] + -- 4-bit + -- overlap + -- + -- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices + -- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples + -- [-----][--------full 12-bit samples--------][---] + -- 8-bit 8-bit + -- overlap overlap + -- + -- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices + -- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples + -- [--------full 12-bit samples-----------][-----] + -- 4-bit + -- overlap + -- + -- Note: Samples with apostrophes (') indicate partial samples that span + -- across cycle boundaries. The complete samples are reconstructed by + -- combining these partial segments from different cycles. + function pack_sc12q11( sc : sample_controls_t; + ss : sample_streams_t; + d : unsigned ) return unsigned is + constant IQ_PAIR_LEN : positive := 24; + variable rv : unsigned(d'range) := (others => '0'); + begin + rv := d; + for i in sc'range loop + if( (sc(i).enable = '1') and (ss(i).data_v = '1') ) then + rv := unsigned(ss(i).data_q(11 downto 0)) & + unsigned(ss(i).data_i(11 downto 0)) & + rv(rv'high downto rv'low+IQ_PAIR_LEN); + end if; + end loop; + return rv; + end function; + procedure handle_fifo_write( signal fifo_current : in fifo_fsm_t; signal meta_current : in meta_fsm_t; @@ -459,11 +514,18 @@ begin if( write_req = '1' ) then if( fifo_current.samples_left = 0 ) then fifo_future.samples_left <= NUM_STREAMS - count_enabled_channels(in_sample_controls); + fifo_future.fifo_write <= write_req; + if( eight_bit_mode_en = '1' ) then fifo_future.fifo_write <= write_req and fifo_current.eight_bit_delay; fifo_future.eight_bit_delay <= not fifo_current.eight_bit_delay; - else - fifo_future.fifo_write <= write_req; + end if; + + if( highly_packed_mode_en = '1' ) then + fifo_future.write_cycle <= (fifo_current.write_cycle + 1) mod 4; + if fifo_current.write_cycle = 0 then + fifo_future.fifo_write <= '0'; + end if; end if; else -- MIMO PACKER: STEP 3 of 3 @@ -489,14 +551,33 @@ begin -- MIMO PACKER: STEP 1 of 3 if( packet_en = '0' ) then + fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r, + fifo_current.in_samples_r, + fifo_current.fifo_data); + + if( highly_packed_mode_en = '1' ) then + fifo_future.fifo_12b_buf <= pack_sc12q11( + sc => in_sample_controls, + ss => in_samples, + d => fifo_current.fifo_12b_buf + ); + + if fifo_current.write_cycle = 1 then + fifo_future.fifo_data <= fifo_current.fifo_12b_buf( + fifo_data'length-1 downto fifo_current.fifo_12b_buf'low); + elsif fifo_current.write_cycle = 2 then + fifo_future.fifo_data <= fifo_current.fifo_12b_buf( + fifo_data'length-1+16 downto fifo_current.fifo_12b_buf'low+16); + elsif fifo_current.write_cycle = 3 then + fifo_future.fifo_data <= fifo_current.fifo_12b_buf( + fifo_data'length-1+32 downto fifo_current.fifo_12b_buf'low+32); + end if; + end if; + if( eight_bit_mode_en = '1' ) then fifo_future.fifo_data <= pack_eight_bit_mode(fifo_current.in_sample_controls_r, fifo_current.in_samples_r, fifo_current.fifo_data); - else - fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r, - fifo_current.in_samples_r, - fifo_current.fifo_data); end if; end if; From b69124573936ac9c5397623ef7fb0d06eee8b875 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Fri, 4 Oct 2024 14:14:00 -0500 Subject: [PATCH 25/41] hdl: added sc16q11 packed tb --- .../modelsim/fx3_gpif_iq_packed_tb.do | 13 + .../vhdl/tb/fx3_gpif_iq_packed_tb.vhd | 646 ++++++++++++++++++ 2 files changed, 659 insertions(+) create mode 100644 hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_packed_tb.do create mode 100644 hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd diff --git a/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_packed_tb.do b/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_packed_tb.do new file mode 100644 index 00000000..649623d3 --- /dev/null +++ b/hdl/fpga/platforms/bladerf-micro/modelsim/fx3_gpif_iq_packed_tb.do @@ -0,0 +1,13 @@ +source ../../../ip/nuand/nuand.do + +# vcom -work nuand -2008 ../vhdl/rx.vhd +# vcom -work nuand -2008 ../vhdl/tx.vhd + +# vlib rtl_work +# vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd + +# compile_nuand ../../../ip/nuand bladerf-micro + +vcom -work nuand -2008 ../../../ip/nuand/simulation/fx3_model.vhd +vcom -work nuand -2008 ../vhdl/tb/fx3_model.vhd +vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_packed_tb.vhd diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd new file mode 100644 index 00000000..ad5a5f37 --- /dev/null +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd @@ -0,0 +1,646 @@ +-- Copyright (c) 2024 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. + +library ieee; + use ieee.std_logic_1164.all; + use ieee.numeric_std.all; + +library rtl_work; + +library altera_lnsim; + use altera_lnsim.altera_pll; + +library nuand; + use nuand.util.all ; + use nuand.fifo_readwrite_p.all; + use nuand.common_dcfifo_p.all; + use nuand.bladerf_p.all; + use nuand.fx3_gpif_p.all; + +entity fx3_gpif_iq_packed_tb is + generic ( + -- For bladeRF2 (2x2 MIMO): + NUM_MIMO_STREAMS : natural := 2; + FIFO_READER_READ_THROTTLE : natural := 0; + + ENABLE_CHANNEL_0 : std_logic := '1'; + ENABLE_CHANNEL_1 : std_logic := '1' + ); +end entity; + +architecture arch of fx3_gpif_iq_packed_tb is + + -- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock + constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0); + + -- For reasons unknown, simulation of this system in ModelSim requires that + -- wrreq and data be asserted shortly before the rising clock edge. Sigh... + constant FIFO_WORKAROUND : time := 1 ps; + + type fx3_control_t is record + usb_speed : std_logic; + tx_enable : std_logic; + rx_enable : std_logic; + meta_enable : std_logic; + packet : std_logic; + highly_packed_mode : std_logic; + end record; + + type fx3_gpif_t is record + gpif_in : std_logic_vector(31 downto 0); + gpif_out : std_logic_vector(31 downto 0); + gpif_oe : std_logic; + ctl_in : std_logic_vector(12 downto 0); + ctl_out : std_logic_vector(12 downto 0); + ctl_oe : std_logic_vector(12 downto 0); + end record; + + signal sys_rst : std_logic := '1'; + signal done : boolean := false; + + signal fx3_pclk : std_logic := '1'; + signal fx3_pclk_pll : std_logic := '1'; + signal sys_clk : std_logic := '1'; + + signal pll_reset : std_logic := '0'; + signal pll_locked : std_logic := '0'; + signal fx3_control : fx3_control_t; + signal fx3_gpif : fx3_gpif_t; + signal fx3_gpif_i : std_logic_vector(31 downto 0); + signal fx3_ctl_i : std_logic_vector(12 downto 0); + + -- Control mapping + alias dma0_rx_ack is fx3_ctl_i( 0); + alias dma1_rx_ack is fx3_ctl_i( 1); + alias dma2_tx_ack is fx3_ctl_i( 2); + alias dma3_tx_ack is fx3_ctl_i( 3); + alias dma_rx_enable is fx3_ctl_i( 4); + alias dma_tx_enable is fx3_ctl_i( 5); + alias dma_idle is fx3_ctl_i( 6); + alias system_reset is fx3_ctl_i( 7); + alias dma0_rx_reqx is fx3_ctl_i( 8); + alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk + alias dma2_tx_reqx is fx3_ctl_i(10); + alias dma3_tx_reqx is fx3_ctl_i(11); + + signal loopback_i : signed(15 downto 0) := (others =>'0'); + signal loopback_q : signed(15 downto 0) := (others =>'0'); + signal loopback_valid : std_logic := '0'; + signal loopback_enabled : std_logic := '0'; + + signal tx_clock : std_logic := '1' ; + signal rx_clock : std_logic := '1' ; + + signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT; + signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT; + signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT; + signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT; + signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT; + + signal rx_mux_i : signed(15 downto 0); + signal rx_mux_q : signed(15 downto 0); + signal rx_mux_valid : std_logic; + + signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' ); + signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' ); + + constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ; + constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ; + constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ; + + signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE); + signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE); + signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE); + signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE); + + signal tx_reset : std_logic := '0'; + signal tx_ts_reset : std_logic := '0'; + signal rx_reset : std_logic := '0'; + signal rx_ts_reset : std_logic := '0'; + + signal meta_en_tx : std_logic := '0'; + signal meta_en_rx : std_logic := '0'; + + signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT; + signal tx_packet_control : packet_control_t; + + signal trigger_signal_sync_tb : std_logic; + signal dac_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' ); + + function data_gen (count : natural) return std_logic_vector is + variable msw, lsw : std_logic_vector(15 downto 0); + begin + msw := std_logic_vector(to_signed(count, 16)); + lsw := std_logic_vector(to_signed(-count, 16)); + + return (msw & lsw); + end function data_gen; + + signal rx_packet_ready : std_logic; + +begin + + -- ======================================================================== + -- Brief summary of data flow + -- ======================================================================== + -- + -- Simulated samples flow from fx3_model's TX side to its RX side. The + -- validity of the data is checked there. + -- + -- entity U_fx3_model FX3 model, TX process + -- signal fx3_gpif_i fx3_gpif.gpif_oe is '0' + -- process register_gpif + -- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA) + -- entity U_fx3_gpif GPIF implementation, write side + -- signal tx_sample_fifo.w* TX fifo, write side + -- entity U_tx_sample_fifo + -- signal tx_sample_fifo.r* TX fifo, read side + -- process tx_mux + -- signal loopback_fifo.w* Loopback fifo, write side + -- entity U_rx_loopback_fifo + -- signal loopback_fifo.r* Loopback fifo, read side + -- process loopback_fifo_control + -- signal loopback_{i,q,valid} + -- process rx_mux + -- signal rx_mux_{i,q,valid} + -- entity U_fifo_writer + -- signal rx_sample_fifo.w* RX fifo, write side + -- entity U_rx_sample_fifo + -- signal rx_sample_fifo.r* RX fifo, read side + -- entity U_fx3_gpif GPIF implementation, read side + -- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3) + -- process register_gpif + -- signal fx3_gpif_i fx3_gpif.gpif_oe is '1' + -- entity U_fx3_model FX3 model, RX process + + + -- ======================================================================== + -- Instantiations + -- ======================================================================== + + -- Unit under test + -- Clock domain: fx3_pclk_pll + U_fx3_gpif : entity nuand.fx3_gpif + port map ( + pclk => fx3_pclk_pll, + reset => sys_rst, + usb_speed => fx3_control.usb_speed, + gpif_in => fx3_gpif.gpif_in, + gpif_out => fx3_gpif.gpif_out, + gpif_oe => fx3_gpif.gpif_oe, + ctl_in => fx3_gpif.ctl_in, + ctl_out => fx3_gpif.ctl_out, + ctl_oe => fx3_gpif.ctl_oe, + tx_enable => fx3_control.tx_enable, + rx_enable => fx3_control.rx_enable, + meta_enable => fx3_control.meta_enable, + packet_enable => fx3_control.packet, + tx_fifo_write => tx_sample_fifo.wreq, + tx_fifo_full => tx_sample_fifo.wfull, + tx_fifo_empty => tx_sample_fifo.wempty, + tx_fifo_usedw => tx_sample_fifo.wused, + tx_fifo_data => tx_sample_fifo.wdata, + tx_timestamp => tx_timestamp, + tx_meta_fifo_write => tx_meta_fifo.wreq, + tx_meta_fifo_full => tx_meta_fifo.wfull, + tx_meta_fifo_empty => tx_meta_fifo.wempty, + tx_meta_fifo_usedw => tx_meta_fifo.wused, + tx_meta_fifo_data => tx_meta_fifo.wdata, + rx_fifo_read => rx_sample_fifo.rreq, + rx_fifo_full => rx_sample_fifo.rfull, + rx_fifo_empty => rx_sample_fifo.rempty, + rx_fifo_usedw => rx_sample_fifo.rused, + rx_fifo_data => rx_sample_fifo.rdata, + rx_meta_fifo_read => rx_meta_fifo.rreq, + rx_meta_fifo_full => rx_meta_fifo.rfull, + rx_meta_fifo_empty => rx_meta_fifo.rempty, + rx_meta_fifo_usedr => rx_meta_fifo.rused, + rx_meta_fifo_data => rx_meta_fifo.rdata + ); + + -- Discrete control signals for fx3_gpif + fx3_control.usb_speed <= '0'; + fx3_control.meta_enable <= '0'; + fx3_control.packet <= '0'; + fx3_control.highly_packed_mode <= '1'; + + U_pkt_gen : entity nuand.rx_packet_generator + port map( + rx_clock => rx_clock, + rx_reset => rx_reset, + rx_enable => fx3_control.rx_enable, + rx_packet_enable => fx3_control.packet, + rx_packet_ready => rx_packet_ready, + rx_packet_control => rx_packet_control + ); + + + meta_en_tx <= fx3_control.meta_enable; + meta_en_rx <= fx3_control.meta_enable; + + increment_tx_ts : process(tx_clock) + variable ping : boolean := true ; + begin + if( rising_edge(tx_clock) ) then + ping := not ping ; + if( ping = true ) then + tx_timestamp <= tx_timestamp + 1 ; + end if ; + end if ; + end process ; + + increment_rx_ts : process(rx_clock) + variable ping : boolean := true ; + begin + if( rising_edge(rx_clock) ) then + ping := not ping ; + if( ping = true ) then + rx_timestamp <= rx_timestamp + 1 ; + end if ; + end if ; + end process ; + + -- Model of FX3's GPIF interface + -- Clock domain: fx3_pclk (source) + U_fx3_model : entity nuand.fx3_model(micro_dma) + port map ( + fx3_pclk => fx3_pclk, + fx3_gpif => fx3_gpif_i, + fx3_ctl => fx3_ctl_i, + fx3_uart_rxd => '0', + fx3_uart_txd => open, + fx3_uart_cts => open, + fx3_rx_en => '1', + fx3_rx_meta_en => meta_en_rx, + fx3_tx_en => '1', + fx3_tx_meta_en => meta_en_tx, + done => done + ); + + -- Generate phase-shifted PLL clock + U_fx3_pll : entity rtl_work.fx3_pll + port map ( + inclk0 => fx3_pclk, + areset => pll_reset, + c0 => fx3_pclk_pll, + locked => pll_locked + ); + + tx_clock <= not tx_clock after TX_HALF_PERIOD ; + rx_clock <= not rx_clock after RX_HALF_PERIOD ; + + + -- Reset handler + sys_rst <= '0' after 100 ns; + + -- Generate system clock + sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0'; + + + tx_reset <= sys_rst; + tx_ts_reset <= sys_rst; + rx_reset <= sys_rst; + rx_ts_reset <= sys_rst; + + meta_en_tx <= fx3_control.meta_enable; + meta_en_rx <= fx3_control.meta_enable; + + -- TX Submodule + U_tx : entity work.tx + generic map ( + NUM_STREAMS => dac_controls'length + ) + port map ( + tx_reset => tx_reset, + tx_clock => tx_clock, + tx_enable => fx3_control.tx_enable, + + meta_en => meta_en_tx, + timestamp_reset => tx_ts_reset, + usb_speed => fx3_control.usb_speed, + tx_underflow_led => open, + tx_timestamp => tx_timestamp, + + -- Triggering + trigger_arm => '0', + trigger_fire => '0', + trigger_master => '0', + trigger_line => open, + + -- Packet FIFO + packet_en => fx3_control.packet, + packet_empty => open, + packet_control => tx_packet_control, + packet_ready => '1', + + -- Samples from host via FX3 + sample_fifo_wclock => fx3_pclk_pll, + sample_fifo_wreq => tx_sample_fifo.wreq, + sample_fifo_wdata => tx_sample_fifo.wdata, + sample_fifo_wempty => tx_sample_fifo.wempty, + sample_fifo_wfull => tx_sample_fifo.wfull, + sample_fifo_wused => tx_sample_fifo.wused, + + -- Metadata from host via FX3 + meta_fifo_wclock => fx3_pclk_pll, + meta_fifo_wreq => tx_meta_fifo.wreq, + meta_fifo_wdata => tx_meta_fifo.wdata, + meta_fifo_wempty => tx_meta_fifo.wempty, + meta_fifo_wfull => tx_meta_fifo.wfull, + meta_fifo_wused => tx_meta_fifo.wused, + + -- Digital Loopback Interface + loopback_enabled => '0', + loopback_fifo_wdata => loopback_fifo.wdata, + loopback_fifo_wreq => loopback_fifo.wreq, + loopback_fifo_wfull => loopback_fifo.wfull, + loopback_fifo_wused => loopback_fifo.wused, + + -- RFFE Interface + dac_controls => dac_controls, + dac_streams => dac_streams + ); + + -- RX Submodule + U_rx : entity work.rx + generic map ( + NUM_STREAMS => adc_controls'length + ) + port map ( + highly_packed_mode_en => fx3_control.highly_packed_mode, + rx_reset => rx_reset, + rx_clock => rx_clock, + rx_enable => fx3_control.rx_enable, + + meta_en => meta_en_rx, + timestamp_reset => rx_ts_reset, + usb_speed => fx3_control.usb_speed, + rx_mux_sel => to_unsigned(0, 3), + rx_overflow_led => open, + rx_timestamp => rx_timestamp, + + -- Triggering + trigger_arm => '0', + trigger_fire => '0', + trigger_master => '0', + trigger_line => open, + trigger_signal_sync_tb => trigger_signal_sync_tb, + + -- Packet FIFO + packet_en => fx3_control.packet, + packet_control => rx_packet_control, + packet_ready => rx_packet_ready, + + -- Samples to host via FX3 + sample_fifo_rclock => fx3_pclk_pll, + sample_fifo_raclr => not fx3_control.rx_enable, + sample_fifo_rreq => rx_sample_fifo.rreq, + sample_fifo_rdata => rx_sample_fifo.rdata, + sample_fifo_rempty => rx_sample_fifo.rempty, + sample_fifo_rfull => rx_sample_fifo.rfull, + sample_fifo_rused => rx_sample_fifo.rused, + + -- Mini expansion signals + mini_exp => "00", + + -- Metadata to host via FX3 + meta_fifo_rclock => fx3_pclk_pll, + meta_fifo_raclr => not fx3_control.rx_enable, + meta_fifo_rreq => rx_meta_fifo.rreq, + meta_fifo_rdata => rx_meta_fifo.rdata, + meta_fifo_rempty => rx_meta_fifo.rempty, + meta_fifo_rfull => rx_meta_fifo.rfull, + meta_fifo_rused => rx_meta_fifo.rused, + + -- Digital Loopback Interface + loopback_fifo_wenabled => open, + loopback_fifo_wreset => tx_reset, + loopback_fifo_wclock => tx_clock, + loopback_fifo_wdata => loopback_fifo.wdata, + loopback_fifo_wreq => loopback_fifo.wreq, + loopback_fifo_wfull => loopback_fifo.wfull, + loopback_fifo_wused => loopback_fifo.wused, + + -- RFFE Interface + adc_controls => adc_controls, + adc_streams => adc_streams + ); + + -- ======================================================================== + -- Data converters + -- ======================================================================== + + gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate + -- The TX side of the AD9361 HDL is a FIFO pull interface + -- that expects a readahead FIFO. It toggles the data request + -- signal every other cycle. This behavior is mimicked here. + process( tx_clock, sys_rst ) + begin + if( sys_rst = '1' ) then + dac_controls <= ( + 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'), + 1 => (enable => ENABLE_CHANNEL_1, data_req => '1') + ); + elsif( rising_edge(tx_clock) ) then + for i in dac_controls'range loop + dac_controls(i) <= ( + enable => dac_controls(i).enable, + data_req => not dac_controls(i).data_req ); + end loop; + end if; + end process; + else generate + dac_controls <= (others => SAMPLE_CONTROL_ENABLE); + end generate; + + gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate + process( rx_clock, sys_rst ) + constant COUNT_RESET : integer := 0; + variable count : integer range -2047 to 2047 := COUNT_RESET; + begin + if( sys_rst = '1' ) then + count := COUNT_RESET; + adc_controls <= ( + 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'), + 1 => (enable => ENABLE_CHANNEL_1, data_req => '1') + ); + elsif( rising_edge(rx_clock) ) then + for i in adc_controls'range loop + adc_controls(i) <= ( + enable => adc_controls(i).enable, + data_req => not adc_controls(i).data_req ); + if( adc_controls(i).enable = '1') then + if( adc_streams(i).data_v = '1' ) then + adc_streams(i).data_i <= to_signed(count, 16); + adc_streams(i).data_q <= to_signed(-count, 16); + if( count < 2047 ) then + count := count + 1; + else + count := COUNT_RESET; + end if; + end if; + adc_streams(i).data_v <= not adc_streams(i).data_v; + end if; + end loop; + end if; + end process; + else generate + adc_controls <= (others => SAMPLE_CONTROL_ENABLE); + end generate; + + -- ======================================================================== + -- Processes + -- ======================================================================== + + -- FX3 GPIF bidirectional signal control + -- Adapted from same process in bladerf-hosted.vhd + register_gpif : process(sys_rst, fx3_pclk_pll) + begin + if( sys_rst = '1' ) then + fx3_gpif_i <= (others => 'Z'); + fx3_gpif.gpif_in <= (others => 'Z'); + elsif( rising_edge(fx3_pclk_pll) ) then + fx3_gpif.gpif_in <= fx3_gpif_i; + + if( fx3_gpif.gpif_oe = '1' ) then + fx3_gpif_i <= fx3_gpif.gpif_out; + else + fx3_gpif_i <= (others =>'Z'); + end if; + end if; + end process; + + -- FX3 CTL bidirectional signals + -- Adapted from same generator in bladerf-hosted.vhd + generate_ctl : for i in fx3_ctl_i'range generate + fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z'; + end generate; + + fx3_gpif.ctl_in <= fx3_ctl_i; + + -- Controller for loopback FIFO + -- Stripped-down version of same process from rx.vhd + loopback_fifo_control : process( sys_rst, loopback_fifo.rclock ) + begin + if( sys_rst = '1' ) then + loopback_enabled <= '0'; + loopback_fifo.rreq <= '0'; + loopback_i <= (others => '0'); + loopback_q <= (others => '0'); + loopback_valid <= '0'; + elsif( rising_edge(loopback_fifo.rclock) ) then + loopback_enabled <= '0'; + loopback_fifo.rreq <= '0'; + loopback_i <= loopback_i; + loopback_q <= loopback_q; + loopback_valid <= '0'; + + -- Is loopback enabled? + loopback_enabled <= fx3_control.rx_enable; + + -- Do the loopback + loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length); + loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length); + loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty; + + -- Read from the FIFO if req'd + loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty); + end if; + end process; + + -- RX multiplexer + -- Stripped-down version of same process from rx.vhd + rx_mux : process(sys_rst, sys_clk) + begin + if( sys_rst = '1' ) then + rx_mux_i <= (others =>'0'); + rx_mux_q <= (others =>'0'); + rx_mux_valid <= '0'; + elsif( rising_edge(sys_clk) ) then + rx_mux_i <= loopback_i; + rx_mux_q <= loopback_q; + rx_mux_valid <= loopback_valid; + end if; + end process; + + -- TX multiplexer + -- Stripped-down version of mimo_channel_sel_mux from tx.vhd + --tx_mux : process( sys_clk ) + --begin + -- if( rising_edge(sys_clk) ) then + -- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty; + + -- loopback_fifo.wdata <= tx_sample_fifo.rdata; + -- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty; + -- end if; + --end process; + + + -- ======================================================================== + -- Verification + -- ======================================================================== + + -- + -- Check for fullness on FIFOs + -- + assert (rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning; + assert (tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning; + assert (loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning; + + -- Every three gpif transfers will contain 4 samples. + -- Let's fill and check a 4 sample buffer every 3 pclk cycles. + -- + -- Note: Failure expected after each fx3_model iteration since we lose + -- sample continuity when fifo writer is disabled. + look_for_dropped_rx_samples: process(fx3_pclk_pll) + variable rx_val : integer; + variable gpif_buffer_idx : integer range 0 to 2 := 0; + variable buf_sc12q11 : std_logic_vector(3*fx3_gpif.gpif_out'length-1 downto 0) := (others => '0'); + begin + -- Init rx_val + if sys_rst = '1' then + rx_val := 16#172# when ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1 else 16#B9#; + end if; + + if (rising_edge(fx3_pclk_pll) + and fx3_gpif.gpif_oe = '1' + and fx3_control.rx_enable = '1') then + + -- Shift in the new samples + buf_sc12q11 := fx3_gpif.gpif_out & buf_sc12q11(buf_sc12q11'length-1 downto fx3_gpif.gpif_out'length); + + -- Checks the 4 sample buffer every 3 pclk cycles + if gpif_buffer_idx = 2 then + for i in 0 to 3 loop + assert(signed(buf_sc12q11(11+24*i downto 24*i))) = to_signed(rx_val, 12) + report "I expected: " & integer'image(rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(11+24*i downto 24*i)))) + severity failure; + assert(signed(buf_sc12q11(23+24*i downto 12+24*i))) = to_signed(-1*rx_val, 12) + report "Q expected: " & integer'image(-1*rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(23+24*i downto 12+24*i)))) + severity failure; + rx_val := (rx_val + 1) mod 2048; + end loop; + end if; + + gpif_buffer_idx := (gpif_buffer_idx + 1) mod 3; + end if; + end process look_for_dropped_rx_samples; + +end architecture; From 0789be9bbe8b618a50c89b0a2853e28e2eee316f Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 26 Mar 2024 15:52:01 -0500 Subject: [PATCH 26/41] hdl: added sc16q11 packed enable signal from Nios GPIO --- .../bladerf-micro/vhdl/bladerf-hosted.vhd | 16 +++++++++++++++- .../platforms/bladerf-micro/vhdl/bladerf_p.vhd | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd index 5d634e5d..f51b836a 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd @@ -93,6 +93,8 @@ architecture hosted_bladerf of bladerf is signal eightbit_en_tx : std_logic; signal eightbit_en_rx : std_logic; + signal highly_packed_en_txrx : std_logic; + signal packet_en_pclk : std_logic; signal packet_en_tx : std_logic; signal packet_en_rx : std_logic; @@ -641,8 +643,9 @@ begin trigger_master => rx_trigger_ctl.master, trigger_line => rx_trigger_line, - -- Eightbit mode + -- Packed modes eight_bit_mode_en => eightbit_en_rx, + highly_packed_mode_en => highly_packed_en_txrx, -- Packet FIFO packet_en => packet_en_rx, @@ -859,6 +862,17 @@ begin sync => eightbit_en_tx ); + U_sync_highly_packed_en_txrx : entity work.synchronizer + generic map ( + RESET_LEVEL => '0' + ) + port map ( + reset => '0', + clock => ad9361.clock, + async => nios_gpio.o.highly_packed_en, + sync => highly_packed_en_txrx + ); + U_sync_packet_en_pclk : entity work.synchronizer generic map ( RESET_LEVEL => '0' diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd index 4aa6ee3c..e4147bef 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.vhd @@ -307,6 +307,7 @@ package bladerf_p is type nios_gpo_t is record xb_mode : std_logic_vector(1 downto 0); eightbit_en : std_logic; + highly_packed_en: std_logic; packet_en : std_logic; si_clock_sel : std_logic; ufl_clock_oe : std_logic; @@ -518,6 +519,7 @@ package body bladerf_p is variable rv : std_logic_vector(31 downto 0) := (others => 'U'); begin rv(31 downto 30) := x.xb_mode; + rv(21) := x.highly_packed_en; rv(20) := x.eightbit_en; rv(19) := x.packet_en; rv(18) := x.si_clock_sel; @@ -597,6 +599,7 @@ package body bladerf_p is variable rv : nios_gpo_t; begin rv.xb_mode := x(31 downto 30); + rv.highly_packed_en:= x(21); rv.eightbit_en := x(20); rv.packet_en := x(19); rv.si_clock_sel := x(18); From 224109e7eefc851b8a53a234377e1ed1d4c84c4e Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 23 Sep 2024 11:06:53 -0500 Subject: [PATCH 27/41] libbladeRF: added sc16q11 packed sample format libbladeRF ingests SC12 Q11 samples and expands them to SC16 Q11 before filling the end buffer. The trade-off is CPU cycles for the 12b to 16b conversion. --- host/libraries/libbladeRF/include/bladeRF1.h | 5 +++++ .../libraries/libbladeRF/include/libbladeRF.h | 16 ++++++++++++++ .../libbladeRF/src/board/bladerf2/common.c | 7 ++++++ .../libbladeRF/src/helpers/interleave.c | 2 ++ .../libbladeRF/src/streaming/format.h | 16 ++++++++++++++ .../libraries/libbladeRF/src/streaming/sync.c | 22 ++++++++++++++++--- 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/host/libraries/libbladeRF/include/bladeRF1.h b/host/libraries/libbladeRF/include/bladeRF1.h index 5c09f655..8c939e95 100644 --- a/host/libraries/libbladeRF/include/bladeRF1.h +++ b/host/libraries/libbladeRF/include/bladeRF1.h @@ -1376,6 +1376,11 @@ int CALL_CONV bladerf_calibrate_dc(struct bladerf *dev, */ #define BLADERF_GPIO_8BIT_MODE (1 << 20) +/** + * Enable highly packed mode + */ +#define BLADERF_GPIO_HIGHLY_PACKED_MODE (1 << 21) + /** * AGC enable control bit * diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 4b5f1ece..ce3f563c 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -2140,6 +2140,22 @@ typedef enum { */ BLADERF_FORMAT_SC16_Q11, + /** + * @brief Signed, Complex 16-bit Q11 using a 12-bit Q11 intermediate format. + * + * This format is a ::BLADERF_FORMAT_SC16_Q11 equivalent to the end user. + * The difference lies in the intermediate SC12 Q11 packing format used by + * the FPGA and libbladeRF. This intermediate format allows for a 33.3% + * higher sample rate when bandwidth limited by the host interface. Synchronous + * buffer length must be a multiple of 4096 samples. + * + * @note While this format allows for higher sample rates over bandwidth-limited + * interfaces, it requires additional CPU processing for packing/unpacking. Users + * should benchmark to determine if the increased sample rate outweighs the + * added processing overhead for their specific use case. + */ + BLADERF_FORMAT_SC16_Q11_PACKED, + /** * This format is the same as the ::BLADERF_FORMAT_SC16_Q11 format, except * the first 4 samples in every block* of samples are replaced with diff --git a/host/libraries/libbladeRF/src/board/bladerf2/common.c b/host/libraries/libbladeRF/src/board/bladerf2/common.c index 15202f89..60a02699 100644 --- a/host/libraries/libbladeRF/src/board/bladerf2/common.c +++ b/host/libraries/libbladeRF/src/board/bladerf2/common.c @@ -54,6 +54,7 @@ static inline int requires_timestamps(bladerf_format format, bool *required) case BLADERF_FORMAT_SC8_Q7: case BLADERF_FORMAT_SC16_Q11: + case BLADERF_FORMAT_SC16_Q11_PACKED: *required = false; break; @@ -123,6 +124,12 @@ int perform_format_config(struct bladerf *dev, gpio_val &= ~BLADERF_GPIO_8BIT_MODE; } + if (format == BLADERF_FORMAT_SC16_Q11_PACKED) { + gpio_val |= BLADERF_GPIO_HIGHLY_PACKED_MODE; + } else { + gpio_val &= ~BLADERF_GPIO_HIGHLY_PACKED_MODE; + } + CHECK_STATUS(dev->backend->config_gpio_write(dev, gpio_val)); board_data->module_format[dir] = format; diff --git a/host/libraries/libbladeRF/src/helpers/interleave.c b/host/libraries/libbladeRF/src/helpers/interleave.c index 0989c4c9..a62d551b 100644 --- a/host/libraries/libbladeRF/src/helpers/interleave.c +++ b/host/libraries/libbladeRF/src/helpers/interleave.c @@ -46,6 +46,7 @@ size_t _interleave_calc_bytes_per_sample(bladerf_format format) case BLADERF_FORMAT_SC8_Q7_META: return 2; + case BLADERF_FORMAT_SC16_Q11_PACKED: case BLADERF_FORMAT_SC16_Q11: case BLADERF_FORMAT_SC16_Q11_META: case BLADERF_FORMAT_PACKET_META: @@ -63,6 +64,7 @@ size_t _interleave_calc_metadata_bytes(bladerf_format format) case BLADERF_FORMAT_PACKET_META: return 0x10; case BLADERF_FORMAT_SC8_Q7: + case BLADERF_FORMAT_SC16_Q11_PACKED: case BLADERF_FORMAT_SC16_Q11: return 0; } diff --git a/host/libraries/libbladeRF/src/streaming/format.h b/host/libraries/libbladeRF/src/streaming/format.h index 95cf5dae..2d665cac 100644 --- a/host/libraries/libbladeRF/src/streaming/format.h +++ b/host/libraries/libbladeRF/src/streaming/format.h @@ -54,6 +54,18 @@ static inline size_t sc16q11_to_bytes(size_t n_samples) return n_samples * sample_size; } +/* + * Convert SC16Q11 packed (SC12Q11) samples to bytes + * I and Q are packed into 3 bytes. I and Q are 12 bits each. + * That makes a sample 24 bits = 3 bytes. + */ +static inline size_t sc16q11_packed_to_bytes(size_t n_samples) +{ + const size_t sample_size = 3*sizeof(int8_t); + assert(n_samples <= (SIZE_MAX / sample_size)); + return n_samples * sample_size; +} + /* * Convert bytes to SC16Q11 samples */ @@ -72,6 +84,9 @@ static inline size_t samples_to_bytes(bladerf_format format, size_t n) case BLADERF_FORMAT_SC8_Q7_META: return sc8q7_to_bytes(n); + case BLADERF_FORMAT_SC16_Q11_PACKED: + return sc16q11_packed_to_bytes(n); + case BLADERF_FORMAT_SC16_Q11: case BLADERF_FORMAT_SC16_Q11_META: return sc16q11_to_bytes(n); @@ -93,6 +108,7 @@ static inline size_t bytes_to_samples(bladerf_format format, size_t n) case BLADERF_FORMAT_SC8_Q7_META: return bytes_to_sc8q7(n); + case BLADERF_FORMAT_SC16_Q11_PACKED: case BLADERF_FORMAT_SC16_Q11: case BLADERF_FORMAT_SC16_Q11_META: return bytes_to_sc16q11(n); diff --git a/host/libraries/libbladeRF/src/streaming/sync.c b/host/libraries/libbladeRF/src/streaming/sync.c index 600dde8f..706e1787 100644 --- a/host/libraries/libbladeRF/src/streaming/sync.c +++ b/host/libraries/libbladeRF/src/streaming/sync.c @@ -536,6 +536,7 @@ int sync_rx(struct bladerf_sync *s, void *samples, unsigned num_samples, switch (s->stream_config.format) { case BLADERF_FORMAT_SC16_Q11: + case BLADERF_FORMAT_SC16_Q11_PACKED: case BLADERF_FORMAT_SC8_Q7: s->state = SYNC_STATE_USING_BUFFER; break; @@ -567,9 +568,24 @@ int sync_rx(struct bladerf_sync *s, void *samples, unsigned num_samples, samples_to_copy = uint_min(num_samples - samples_returned, samples_per_buffer - b->partial_off); - memcpy(samples_dest + samples2bytes(s, samples_returned), - buf_src + samples2bytes(s, b->partial_off), - samples2bytes(s, samples_to_copy)); + if (s->stream_config.format == BLADERF_FORMAT_SC16_Q11_PACKED) { + // Unpack SC12Q11 samples to SC16Q11 directly into destination buffer + size_t zz, jj; + uint8_t *meta_sample_ptr = buf_src + samples2bytes(s, b->partial_off); + int16_t *dest_ptr = (int16_t*)(samples_dest + (4*samples_returned)); + for (zz = 0, jj = 0; zz < 2*samples_to_copy; zz+=4, jj+=3) { + dest_ptr[zz+0] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+0] & 0x0FFF) << 4) >> 4; + dest_ptr[zz+1] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+1] & 0x00FF) << 8) >> 4 + | ((((uint16_t*)(meta_sample_ptr))[jj+0] & 0xF000) >> 12); + dest_ptr[zz+2] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+2] & 0x000F) << 12) >> 4 + | ((((uint16_t*)(meta_sample_ptr))[jj+1] & 0xFF00)) >> 8; + dest_ptr[zz+3] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+2] & 0xFFF0)) >> 4; + } + } else { + memcpy(samples_dest + samples2bytes(s, samples_returned), + buf_src + samples2bytes(s, b->partial_off), + samples2bytes(s, samples_to_copy)); + } b->partial_off += samples_to_copy; samples_returned += samples_to_copy; From 261c6a6f00d88aac33223945489ac8fbd27f42e3 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 3 Oct 2024 16:23:34 -0500 Subject: [PATCH 28/41] hdl: fixed sc16q11 packed discontinuity on RX overflow The 12b write cycle and buffer are held constant when in the HOLDOFF state. --- hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd index 43c52790..3407890b 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_writer.vhd @@ -659,10 +659,13 @@ begin if( fifo_full = '1' or ( meta_current.meta_written = '0' and meta_en = '1') ) then fifo_future.fifo_write <= '0'; fifo_future.state <= HOLDOFF; + fifo_future.write_cycle <= fifo_current.write_cycle; + fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf; end if; when HOLDOFF => - + fifo_future.write_cycle <= fifo_current.write_cycle; + fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf; if( fifo_enough ) then fifo_future.state <= WRITE_SAMPLES; From a9108732fe54df153dacdb424f231b0d83d4d665 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 8 Oct 2024 17:08:08 -0500 Subject: [PATCH 29/41] hdl: added sc16q11 packed tx sample drop check --- .../vhdl/tb/fx3_gpif_iq_packed_tb.vhd | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd index ad5a5f37..89fce653 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd @@ -643,4 +643,34 @@ begin end if; end process look_for_dropped_rx_samples; + look_for_dropped_tx_samples: process(tx_clock) + variable tx_val : integer := 0; + variable message_count : integer := 1; + variable q_expected : integer := 0; + variable valid_tx_count : integer := 0; + begin + if rising_edge(tx_clock) then + for i in dac_controls'range loop + if dac_streams(i).data_v = '1' then + q_expected := to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8)); + + assert(dac_streams(i).data_i = to_signed(tx_val, 16)) + report "TX("&integer'image(i)&") I expected: " & integer'image(tx_val) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_i))) + severity failure; + assert(dac_streams(i).data_q = q_expected) + report "TX("&integer'image(i)&") Q expected: " & integer'image(q_expected) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_q))) + severity failure; + + -- A new message is received every 2048 samples + valid_tx_count := valid_tx_count + 1; + if valid_tx_count mod 2048 = 0 then + message_count := message_count + 1; + end if; + + tx_val := (tx_val + 2) mod 2048; + end if; + end loop; + end if; + end process look_for_dropped_tx_samples; + end architecture; From de0e10e58342c6436e9d72adeb46f12caf467ef1 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 9 Oct 2024 17:24:37 -0500 Subject: [PATCH 30/41] hdl: added sc16q11 packed format to fx3 model Every 3 gpif cycles will contain 4 sc12q11 samples when the packed format is enabled. --- hdl/fpga/ip/nuand/simulation/fx3_model.vhd | 1 + .../vhdl/tb/fx3_gpif_iq_packed_tb.vhd | 1 + .../bladerf-micro/vhdl/tb/fx3_model.vhd | 34 ++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/hdl/fpga/ip/nuand/simulation/fx3_model.vhd b/hdl/fpga/ip/nuand/simulation/fx3_model.vhd index b13b55c1..1dce5e00 100644 --- a/hdl/fpga/ip/nuand/simulation/fx3_model.vhd +++ b/hdl/fpga/ip/nuand/simulation/fx3_model.vhd @@ -42,6 +42,7 @@ entity fx3_model is fx3_tx_en : in std_logic; fx3_tx_meta_en : in std_logic; eight_bit_mode_en : in std_logic := '0'; + packed_mode_en : in std_logic := '0'; done : out boolean ); end entity ; -- fx3_model diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd index 89fce653..c63a0459 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd @@ -291,6 +291,7 @@ begin fx3_rx_meta_en => meta_en_rx, fx3_tx_en => '1', fx3_tx_meta_en => meta_en_tx, + packed_mode_en => fx3_control.highly_packed_mode, done => done ); diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd index be1682a9..27bdf9a0 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model.vhd @@ -58,6 +58,32 @@ architecture micro_dma of fx3_model is signal rx_data : std_logic_vector(31 downto 0); signal tx_data : std_logic_vector(31 downto 0); + -- Generates packed samples + -- The host will pack SC16Q11 samples into an SC12Q11 format. Every 3 gpif_in + -- cycles contain 4 SC12Q11 IQ pairs. + -- + -- Packing order: + -- Buffer 1: [--Sample1(8)--|----------Sample0(24)----------] + -- Buffer 2: [------Sample2(16)------|------Sample1(16)-----] + -- Buffer 3: [----------Sample3(24)----------|--Sample2(8)--] + function data_gen_packed(cycle : natural) return std_logic_vector is + variable four_sample_buffer : std_logic_vector(95 downto 0) := (others => '0'); + variable buffer_offset : integer := 0; + variable sample_value_ref : integer := 0; + variable I : std_logic_vector(11 downto 0) := (others => '0'); + variable Q : std_logic_vector(11 downto 0) := (others => '0'); + begin + sample_value_ref := cycle / 3; + for j in 0 to 3 loop + Q := std_logic_vector(to_signed(8*sample_value_ref+2*j+1, 12)); + I := std_logic_vector(to_signed(8*sample_value_ref+2*j, 12)); + four_sample_buffer := Q & I & four_sample_buffer(95 downto 24); + end loop; + + buffer_offset := (cycle mod 3) * 32; + return four_sample_buffer(31+buffer_offset downto buffer_offset); + end function data_gen_packed; + impure function data_gen (count : natural) return std_logic_vector is variable eight_bit_msw_i : std_logic_vector(7 downto 0); variable eight_bit_msw_q : std_logic_vector(7 downto 0); @@ -155,6 +181,7 @@ begin constant TIME_BETWEEN_ITERATIONS : natural := 7000; constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; variable count : natural := START_COUNT; + variable cycle : natural := 0; variable timestamp_cntr : natural := 400; variable header_len : natural := 0; variable data_out : std_logic_vector(31 downto 0); @@ -224,7 +251,11 @@ begin for i in 1 to (BLOCK_SIZE - header_len) loop gpif_state_tx <= TX_SAMPLES; data_out := data_gen(count); - if( eight_bit_mode_en = '1' ) then + if packed_mode_en = '1' then + data_out := data_gen_packed(cycle); + end if; + + if( eight_bit_mode_en = '1' or packed_mode_en = '1' ) then fx3_gpif <= data_out; tx_data <= data_out; else @@ -233,6 +264,7 @@ begin end if; wait until rising_edge( fx3_pclk ); + cycle := cycle + 1; count := (count + 4) mod 128 when eight_bit_mode_en = '1' else (count + 2) mod 2048; gpif_state_tx <= IDLE; From b86be34e0c39da510ac817d53f2c6e2b74b52dad Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Thu, 27 Feb 2025 18:03:36 -0600 Subject: [PATCH 31/41] hdl: added sc16q11 packed tx support --- hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd | 88 ++++++++++++++++++- .../bladerf-micro/vhdl/bladerf-hosted.vhd | 1 + .../vhdl/tb/fx3_gpif_iq_packed_tb.vhd | 8 +- hdl/fpga/platforms/bladerf-micro/vhdl/tx.vhd | 6 +- .../platforms/bladerf/vhdl/bladerf-hosted.vhd | 1 + 5 files changed, 96 insertions(+), 8 deletions(-) diff --git a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd index 848155ea..b5077288 100644 --- a/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd +++ b/hdl/fpga/ip/nuand/synthesis/fifo_reader.vhd @@ -44,6 +44,7 @@ entity fifo_reader is meta_en : in std_logic; packet_en : in std_logic; eight_bit_mode_en : in std_logic; + highly_packed_mode_en : in std_logic; timestamp : in unsigned(63 downto 0); fifo_usedw : in std_logic_vector(FIFO_USEDW_WIDTH-1 downto 0); @@ -142,6 +143,10 @@ architecture simple of fifo_reader is fifo_read : std_logic; out_samples : sample_streams_t(out_samples'range); eight_bit_sample_sel: std_logic; + + -- Highly packed mode signals + packed_buffer : std_logic_vector(47 downto 0); + packed_cycle : integer range 0 to 3; end record; constant FIFO_FSM_RESET_VALUE : fifo_fsm_t := ( @@ -157,7 +162,9 @@ architecture simple of fifo_reader is packet_data_cache => (others => '0'), fifo_read => '0', out_samples => (others => ZERO_SAMPLE), - eight_bit_sample_sel => '0' + eight_bit_sample_sel => '0', + packed_buffer => (others => '0'), + packed_cycle => 0 ); signal fifo_current : fifo_fsm_t := FIFO_FSM_RESET_VALUE; @@ -419,6 +426,67 @@ begin return rv; end function; + -- -------------------------------------------------------------------- + -- MIMO UNPACKER: STEP 1 of 5 (SC12Q11 Highly Packed Mode) + -- -------------------------------------------------------------------- + -- The sample FIFO output is a wide data bus that contains multiple + -- 12-bit I/Q samples packed across multiple cycles. This procedure unpacks + -- data from a 64-bit wide bus across three cycles to extract eight 12-bit I/Q pairs. + -- + -- The packing scheme for 12-bit samples across three 64-bit cycles: + -- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices + -- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples + -- [-----][--------full 12-bit samples-----------] + -- 4-bit + -- overlap + -- + -- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices + -- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples + -- [-----][--------full 12-bit samples--------][---] + -- 8-bit 8-bit + -- overlap overlap + -- + -- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices + -- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples + -- [--------full 12-bit samples-----------][-----] + -- 4-bit + -- overlap + -- + -- Note: Samples with apostrophes (') indicate partial samples that span + -- across cycle boundaries. The complete samples are reconstructed by + -- combining these partial segments from different cycles. + procedure unpack_sc12q11( + signal data : in std_logic_vector(63 downto 0); + signal previous_data : in std_logic_vector(47 downto 0); + signal cycle : in integer; + variable rv : out sample_streams_t + ) is + constant OFFSET_UNIT : natural := 24; + begin + for i in rv'range loop + rv(i).data_i := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(11 downto 0)),rv(i).data_i'length); + rv(i).data_q := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(23 downto 12)),rv(i).data_q'length); + rv(i).data_v := '0'; + end loop; + + if (cycle = 1) then + rv(0).data_i := resize(signed(previous_data(43 downto 32)),rv(0).data_i'length); + rv(0).data_q := resize(signed(data(7 downto 0) & previous_data(47 downto 44)),rv(0).data_q'length); + rv(1).data_i := resize(signed(shift_right(unsigned(data),8)(11 downto 0)),rv(1).data_i'length); + rv(1).data_q := resize(signed(shift_right(unsigned(data),8)(23 downto 12)),rv(1).data_q'length); + elsif (cycle = 2) then + rv(0).data_i := resize(signed(previous_data(27 downto 16)),rv(0).data_i'length); + rv(0).data_q := resize(signed(previous_data(39 downto 28)),rv(0).data_q'length); + rv(1).data_i := resize(signed(fifo_data(3 downto 0) & previous_data(47 downto 40)), rv(1).data_i'length); + rv(1).data_q := resize(signed(fifo_data(15 downto 4)), rv(1).data_q'length); + elsif (cycle = 3) then + rv(0).data_i := resize(signed(previous_data(11 downto 0)),rv(0).data_i'length); + rv(0).data_q := resize(signed(previous_data(23 downto 12)),rv(0).data_q'length); + rv(1).data_i := resize(signed(previous_data(35 downto 24)),rv(0).data_i'length); + rv(1).data_q := resize(signed(previous_data(47 downto 36)),rv(0).data_q'length); + end if; + end procedure; + -- -------------------------------------------------------------------- -- MIMO UNPACKER: STEP 3 of 5 -- -------------------------------------------------------------------- @@ -459,7 +527,14 @@ begin fifo_future.packet_control.data_valid <= '0'; -- MIMO UNPACKER: STEP 1 of 5 - if( eight_bit_mode_en = '1') then + if (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then + unpack_sc12q11( + data => fifo_data, + previous_data => fifo_current.packed_buffer, + cycle => fifo_current.packed_cycle, + rv => unpacked + ); + elsif (eight_bit_mode_en = '1') then unpacked := unpack_eight_bit_mode(fifo_current.sample_controls_reg, fifo_data, fifo_current.eight_bit_sample_sel); else unpacked := unpack(fifo_current.sample_controls_reg, fifo_data); @@ -566,11 +641,16 @@ begin if( fifo_current.samples_left = 0 ) then fifo_future.samples_left <= fifo_current.samples_left_init; fifo_future.ch_shift <= 0; + fifo_future.fifo_read <= read_req; if( eight_bit_mode_en = '1' ) then fifo_future.fifo_read <= read_req and fifo_current.eight_bit_sample_sel; fifo_future.eight_bit_sample_sel <= not fifo_current.eight_bit_sample_sel; - else - fifo_future.fifo_read <= read_req; + elsif (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then + fifo_future.packed_cycle <= (fifo_current.packed_cycle + 1) mod 4; + fifo_future.packed_buffer <= fifo_data(fifo_data'high downto fifo_data'high-47); + if read_req = '1' and fifo_current.packed_cycle = 3 then + fifo_future.fifo_read <= '0'; + end if; end if; else -- MIMO UNPACKER: STEP 5 of 5 diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd index f51b836a..4818f26e 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd @@ -569,6 +569,7 @@ begin -- Eightbit mode eight_bit_mode_en => eightbit_en_tx, + highly_packed_mode_en => highly_packed_en_txrx, -- Packet FIFO packet_en => packet_en_tx, diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd index c63a0459..b3591f9a 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_packed_tb.vhd @@ -339,6 +339,9 @@ begin tx_underflow_led => open, tx_timestamp => tx_timestamp, + -- Packing modes + highly_packed_mode_en => fx3_control.highly_packed_mode, + -- Triggering trigger_arm => '0', trigger_fire => '0', @@ -653,7 +656,8 @@ begin if rising_edge(tx_clock) then for i in dac_controls'range loop if dac_streams(i).data_v = '1' then - q_expected := to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8)); + q_expected := tx_val+1 when fx3_control.highly_packed_mode = '1' + else to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8)); assert(dac_streams(i).data_i = to_signed(tx_val, 16)) report "TX("&integer'image(i)&") I expected: " & integer'image(tx_val) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_i))) @@ -668,7 +672,7 @@ begin message_count := message_count + 1; end if; - tx_val := (tx_val + 2) mod 2048; + tx_val := (tx_val + 2) when tx_val < 2046 else -2048; end if; end loop; end if; diff --git a/hdl/fpga/platforms/bladerf-micro/vhdl/tx.vhd b/hdl/fpga/platforms/bladerf-micro/vhdl/tx.vhd index 7dd307df..cf004e69 100644 --- a/hdl/fpga/platforms/bladerf-micro/vhdl/tx.vhd +++ b/hdl/fpga/platforms/bladerf-micro/vhdl/tx.vhd @@ -47,8 +47,9 @@ entity tx is trigger_master : in std_logic; trigger_line : inout std_logic; -- this is not good, should be in/out/oe - -- 8-bit mode - eight_bit_mode_en : in std_logic := '0'; + -- Packing modes + eight_bit_mode_en : in std_logic := '0'; + highly_packed_mode_en : in std_logic := '0'; -- Packet from host via FX3 packet_en : in std_logic; @@ -218,6 +219,7 @@ begin timestamp => tx_timestamp, eight_bit_mode_en => eight_bit_mode_en, + highly_packed_mode_en => highly_packed_mode_en, fifo_empty => sample_fifo.rempty, fifo_usedw => sample_fifo.rused, diff --git a/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd b/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd index 504750e8..2dc8edd5 100644 --- a/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd +++ b/hdl/fpga/platforms/bladerf/vhdl/bladerf-hosted.vhd @@ -920,6 +920,7 @@ begin meta_en => meta_en_tx, packet_en => packet_en_tx, eight_bit_mode_en => '0', + highly_packed_mode_en => '0', timestamp => tx_timestamp, fifo_empty => tx_sample_fifo.rempty, From 01082ec1b3ac1c122b68b4223682d1c904cfdcf0 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 16 Oct 2024 12:25:01 -0500 Subject: [PATCH 32/41] libbladeRF: added sc16q11 packed tx support --- .../libraries/libbladeRF/src/streaming/sync.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/host/libraries/libbladeRF/src/streaming/sync.c b/host/libraries/libbladeRF/src/streaming/sync.c index 706e1787..94d29a45 100644 --- a/host/libraries/libbladeRF/src/streaming/sync.c +++ b/host/libraries/libbladeRF/src/streaming/sync.c @@ -1067,6 +1067,7 @@ int sync_tx(struct bladerf_sync *s, switch (s->stream_config.format) { case BLADERF_FORMAT_SC16_Q11: + case BLADERF_FORMAT_SC16_Q11_PACKED: case BLADERF_FORMAT_SC8_Q7: s->state = SYNC_STATE_USING_BUFFER; break; @@ -1100,9 +1101,24 @@ int sync_tx(struct bladerf_sync *s, samples_to_copy = uint_min(num_samples - samples_written, samples_per_buffer - b->partial_off); - memcpy(buf_dest + samples2bytes(s, b->partial_off), - samples_src + samples2bytes(s, samples_written), - samples2bytes(s, samples_to_copy)); + if (s->stream_config.format == BLADERF_FORMAT_SC16_Q11_PACKED) { + // Pack SC16Q11 samples to SC12Q11 directly into destination buffer + size_t zz, jj; + uint8_t *packed_dest = buf_dest + samples2bytes(s, b->partial_off); + int16_t const *src_ptr = (int16_t const *)(samples_src + 2*sizeof(int16_t)*samples_written); + for (zz = 0, jj = 0; zz < samples_to_copy * 2; zz += 4, jj += 3) { + ((uint16_t*)packed_dest)[jj+0] = src_ptr[zz+0] & 0x0FFF; + ((uint16_t*)packed_dest)[jj+0] |= (src_ptr[zz+1] << 12) & 0xF000; + ((uint16_t*)packed_dest)[jj+1] = (src_ptr[zz+1] >> 4) & 0x00FF; + ((uint16_t*)packed_dest)[jj+1] |= (src_ptr[zz+2] << 8) & 0xFF00; + ((uint16_t*)packed_dest)[jj+2] = (src_ptr[zz+2] >> 8) & 0x000F; + ((uint16_t*)packed_dest)[jj+2] |= (src_ptr[zz+3] << 4) & 0xFFF0; + } + } else { + memcpy(buf_dest + samples2bytes(s, b->partial_off), + samples_src + samples2bytes(s, samples_written), + samples2bytes(s, samples_to_copy)); + } b->partial_off += samples_to_copy; samples_written += samples_to_copy; From caa254a724d8aefb05253ad85f07662d3faa05b3 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 21 Oct 2024 12:14:57 -0500 Subject: [PATCH 33/41] libbladeRF: added sc16q11 packed error when initializing async stream BLADERF_FORMAT_SC16_Q11_PACKED is only supported with the synchronous interface. --- host/libraries/libbladeRF/src/bladerf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/host/libraries/libbladeRF/src/bladerf.c b/host/libraries/libbladeRF/src/bladerf.c index f19c3a68..cd74b181 100644 --- a/host/libraries/libbladeRF/src/bladerf.c +++ b/host/libraries/libbladeRF/src/bladerf.c @@ -1115,6 +1115,12 @@ int bladerf_init_stream(struct bladerf_stream **stream, } } + if (format == BLADERF_FORMAT_SC16_Q11_PACKED) { + log_error("%s: Async interface does not support SC16_Q11_PACKED format\n", __FUNCTION__); + MUTEX_UNLOCK(&dev->lock); + return BLADERF_ERR_UNSUPPORTED; + } + status = dev->board->init_stream(stream, dev, callback, buffers, num_buffers, format, samples_per_buffer, num_transfers, data); From fb95949ebad5ceb5a53a836cf6c041cd08074578 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 1 Oct 2024 15:12:28 -0500 Subject: [PATCH 34/41] bladeRF-cli: sample format tracked by cli state This will allow us to track the sample format across the cli and can replace the bit_mode cli state member. --- .../bladeRF-cli/src/cmd/printset_impl.c | 24 +++++++++++++++---- host/utilities/bladeRF-cli/src/cmd/rx.c | 6 +---- host/utilities/bladeRF-cli/src/cmd/tx.c | 6 +---- host/utilities/bladeRF-cli/src/common.c | 1 + host/utilities/bladeRF-cli/src/common.h | 1 + 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c index ae1d4013..b445d926 100644 --- a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c +++ b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c @@ -1303,7 +1303,20 @@ out: int print_bitmode(struct cli_state *state, int argc, char **argv) { int rv = CLI_RET_OK; - printf(" Bit Mode: %s bit samples\n", state->bit_mode_8bit ? "8" : "16"); + const char *mode_str; + + switch (state->sample_format) { + case BLADERF_FORMAT_SC16_Q11: + mode_str = "16 bit"; + break; + case BLADERF_FORMAT_SC8_Q7: + mode_str = "8 bit"; + break; + default: + mode_str = "Unknown"; + } + + printf(" Bit Mode: %s samples\n", mode_str); return rv; } @@ -1336,18 +1349,19 @@ int set_bitmode(struct cli_state *state, int argc, char **argv) printf(" Error: 16bit mode not permitted when\n" " over sampling is enabled.\n"); goto out; - } else if(state->bit_mode_8bit) { - state->bit_mode_8bit = false; } + + state->bit_mode_8bit = false; + state->sample_format = BLADERF_FORMAT_SC16_Q11; } else if (!strcasecmp("8", argv[2]) || !strcasecmp("8bit", argv[2])) { if (!state->bit_mode_8bit) { if (strcmp(bladerf_get_board_name(state->dev), "bladerf2") != 0) { printf(" Error: BladeRF2 required for 8bit format\n"); rv = CLI_RET_UNSUPPORTED; goto out; - } else { - state->bit_mode_8bit = true; } + state->bit_mode_8bit = true; + state->sample_format = BLADERF_FORMAT_SC8_Q7; } } else { printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]); diff --git a/host/utilities/bladeRF-cli/src/cmd/rx.c b/host/utilities/bladeRF-cli/src/cmd/rx.c index 64a083cd..0835a566 100644 --- a/host/utilities/bladeRF-cli/src/cmd/rx.c +++ b/host/utilities/bladeRF-cli/src/cmd/rx.c @@ -311,7 +311,6 @@ void *rx_task(void *cli_state_arg) struct cli_state *cli_state = (struct cli_state *)cli_state_arg; struct rxtx_data *rx = cli_state->rx; struct rx_params *rx_params = rx->params; - bladerf_format sync_fmt; task_state = rxtx_get_state(rx); assert(task_state == RXTX_STATE_INIT); @@ -370,12 +369,9 @@ void *rx_task(void *cli_state_arg) if (status == 0) { MUTEX_LOCK(&rx->data_mgmt.lock); - sync_fmt = cli_state->bit_mode_8bit ? - BLADERF_FORMAT_SC8_Q7 : BLADERF_FORMAT_SC16_Q11; - status = bladerf_sync_config( cli_state->dev, rx->data_mgmt.layout, - sync_fmt, rx->data_mgmt.num_buffers, + cli_state->sample_format, rx->data_mgmt.num_buffers, rx->data_mgmt.samples_per_buffer, rx->data_mgmt.num_transfers, rx->data_mgmt.timeout_ms); diff --git a/host/utilities/bladeRF-cli/src/cmd/tx.c b/host/utilities/bladeRF-cli/src/cmd/tx.c index 03ab5904..d4ddeb08 100644 --- a/host/utilities/bladeRF-cli/src/cmd/tx.c +++ b/host/utilities/bladeRF-cli/src/cmd/tx.c @@ -375,7 +375,6 @@ void *tx_task(void *cli_state_arg) enum rxtx_state task_state; struct cli_state *cli_state = (struct cli_state *)cli_state_arg; struct rxtx_data *tx = cli_state->tx; - bladerf_format sync_fmt; /* We expect to be in the IDLE state when this is kicked off. We could * also get into the shutdown state if the program exits before we @@ -408,13 +407,10 @@ void *tx_task(void *cli_state_arg) assert(tx->file_mgmt.file != NULL); MUTEX_UNLOCK(&tx->file_mgmt.file_meta_lock); - sync_fmt = cli_state->bit_mode_8bit ? - BLADERF_FORMAT_SC8_Q7 : BLADERF_FORMAT_SC16_Q11; - /* Initialize the TX synchronous data configuration */ status = bladerf_sync_config( cli_state->dev, tx->data_mgmt.layout, - sync_fmt, tx->data_mgmt.num_buffers, + cli_state->sample_format, tx->data_mgmt.num_buffers, tx->data_mgmt.samples_per_buffer, tx->data_mgmt.num_transfers, tx->data_mgmt.timeout_ms); diff --git a/host/utilities/bladeRF-cli/src/common.c b/host/utilities/bladeRF-cli/src/common.c index 5c6d4a6a..5c1bd207 100644 --- a/host/utilities/bladeRF-cli/src/common.c +++ b/host/utilities/bladeRF-cli/src/common.c @@ -100,6 +100,7 @@ struct cli_state *cli_state_create() cli_state->last_lib_error = 0; cli_state->scripts = NULL; cli_state->bit_mode_8bit = false; + cli_state->sample_format = BLADERF_FORMAT_SC16_Q11; cli_state->dev_info.fpga_size = BLADERF_FPGA_UNKNOWN; cli_state->dev_info.is_bladerf_x40_x115 = false; diff --git a/host/utilities/bladeRF-cli/src/common.h b/host/utilities/bladeRF-cli/src/common.h index 0980940a..137e34b8 100644 --- a/host/utilities/bladeRF-cli/src/common.h +++ b/host/utilities/bladeRF-cli/src/common.h @@ -119,6 +119,7 @@ struct cli_state { struct rxtx_data *tx; /**< Data for sample transmission */ bool bit_mode_8bit; /**< Bit mode is set to 16 bits */ + bladerf_format sample_format; /**< Sample format */ }; /** From ed1292dd7ecff4c53ebcfee84fcf63472167708e Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Fri, 18 Oct 2024 15:52:04 -0500 Subject: [PATCH 35/41] bladeRF-cli: replace cli state member bit_mode_8bit with sample_format Instead of relying on a bit_mode boolean assignment, we can directly rely on a bladerf_format state member. --- host/utilities/bladeRF-cli/src/cmd/generate.c | 2 +- .../utilities/bladeRF-cli/src/cmd/printset_impl.c | 15 ++++++--------- host/utilities/bladeRF-cli/src/cmd/rx.c | 2 +- host/utilities/bladeRF-cli/src/cmd/rxtx.c | 2 +- host/utilities/bladeRF-cli/src/cmd/tx.c | 8 ++++---- host/utilities/bladeRF-cli/src/common.c | 1 - host/utilities/bladeRF-cli/src/common.h | 1 - 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/host/utilities/bladeRF-cli/src/cmd/generate.c b/host/utilities/bladeRF-cli/src/cmd/generate.c index 3ffedf29..e070032c 100644 --- a/host/utilities/bladeRF-cli/src/cmd/generate.c +++ b/host/utilities/bladeRF-cli/src/cmd/generate.c @@ -66,7 +66,7 @@ int cmd_generate(struct cli_state *s, int argc, char **argv) int mag = 2047; int i; - if (s->bit_mode_8bit) { + if (s->sample_format == BLADERF_FORMAT_SC8_Q7) { mag /= 16; } int remaining_argc; diff --git a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c index b445d926..539d5fb2 100644 --- a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c +++ b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c @@ -1351,18 +1351,15 @@ int set_bitmode(struct cli_state *state, int argc, char **argv) goto out; } - state->bit_mode_8bit = false; state->sample_format = BLADERF_FORMAT_SC16_Q11; } else if (!strcasecmp("8", argv[2]) || !strcasecmp("8bit", argv[2])) { - if (!state->bit_mode_8bit) { - if (strcmp(bladerf_get_board_name(state->dev), "bladerf2") != 0) { - printf(" Error: BladeRF2 required for 8bit format\n"); - rv = CLI_RET_UNSUPPORTED; - goto out; - } - state->bit_mode_8bit = true; - state->sample_format = BLADERF_FORMAT_SC8_Q7; + if (strcmp(bladerf_get_board_name(state->dev), "bladerf2") != 0) { + printf(" Error: BladeRF2 required for 8bit format\n"); + rv = CLI_RET_UNSUPPORTED; + goto out; } + + state->sample_format = BLADERF_FORMAT_SC8_Q7; } else { printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]); rv = CLI_RET_UNSUPPORTED; diff --git a/host/utilities/bladeRF-cli/src/cmd/rx.c b/host/utilities/bladeRF-cli/src/cmd/rx.c index 0835a566..42defef9 100644 --- a/host/utilities/bladeRF-cli/src/cmd/rx.c +++ b/host/utilities/bladeRF-cli/src/cmd/rx.c @@ -172,7 +172,7 @@ static int rx_write_csv(struct cli_state *s, MUTEX_LOCK(&rx->file_mgmt.file_lock); - if (s->bit_mode_8bit) { + if (s->sample_format == BLADERF_FORMAT_SC8_Q7) { samples_sc8q7 = (int8_t*)samples; // Output 2 columns for each enabled channel // (2 cols for BLADERF_RX_X1, 4 cols for BLADERF_RX_X2, etc) diff --git a/host/utilities/bladeRF-cli/src/cmd/rxtx.c b/host/utilities/bladeRF-cli/src/cmd/rxtx.c index a5d1867e..af3ba377 100644 --- a/host/utilities/bladeRF-cli/src/cmd/rxtx.c +++ b/host/utilities/bladeRF-cli/src/cmd/rxtx.c @@ -340,7 +340,7 @@ enum rxtx_fmt rxtx_str2fmt(const char *str, struct cli_state *s) if (!strcasecmp("csv", str)) { ret = RXTX_FMT_CSV; } else if (!strcasecmp("bin", str)) { - ret = (s->bit_mode_8bit) ? RXTX_FMT_BIN_SC8Q7 : RXTX_FMT_BIN_SC16Q11; + ret = (s->sample_format == BLADERF_FORMAT_SC8_Q7) ? RXTX_FMT_BIN_SC8Q7 : RXTX_FMT_BIN_SC16Q11; } return ret; diff --git a/host/utilities/bladeRF-cli/src/cmd/tx.c b/host/utilities/bladeRF-cli/src/cmd/tx.c index d4ddeb08..badd5bc8 100644 --- a/host/utilities/bladeRF-cli/src/cmd/tx.c +++ b/host/utilities/bladeRF-cli/src/cmd/tx.c @@ -246,7 +246,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s) int max_val = SC16Q11_IQ_MAX; // 16 bit samples are 2*int8_t samples wide - int sample_size = s->bit_mode_8bit ? 1 : 2; + int sample_size = (s->sample_format == BLADERF_FORMAT_SC8_Q7) ? 1 : 2; int status; assert(tx->file_mgmt.path != NULL); @@ -268,7 +268,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s) } - if (s->bit_mode_8bit) { + if (s->sample_format == BLADERF_FORMAT_SC8_Q7) { min_val = SC8Q7_IQ_MIN; max_val = SC8Q7_IQ_MAX; } @@ -332,7 +332,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s) tx->file_mgmt.format = RXTX_FMT_BIN_SC16Q11; if (n_clamped != 0) { - if (s->bit_mode_8bit) { + if (s->sample_format == BLADERF_FORMAT_SC8_Q7) { printf(" Warning: %zu value%s clamped within DAC SC8 Q7 " "range of [%d, %d].\n", n_clamped, 1 == n_clamped ? "" : "s", SC8Q7_IQ_MIN, @@ -483,7 +483,7 @@ static int tx_cmd_start(struct cli_state *s) status = tx_csv_to_bladerf_format(s); if (status == 0) { - if (s->bit_mode_8bit) { + if (s->sample_format == BLADERF_FORMAT_SC8_Q7) { printf(" Converted CSV to SC8 Q7 file and " "switched to converted file.\n\n"); diff --git a/host/utilities/bladeRF-cli/src/common.c b/host/utilities/bladeRF-cli/src/common.c index 5c1bd207..420a4de1 100644 --- a/host/utilities/bladeRF-cli/src/common.c +++ b/host/utilities/bladeRF-cli/src/common.c @@ -99,7 +99,6 @@ struct cli_state *cli_state_create() cli_state->dev = NULL; cli_state->last_lib_error = 0; cli_state->scripts = NULL; - cli_state->bit_mode_8bit = false; cli_state->sample_format = BLADERF_FORMAT_SC16_Q11; cli_state->dev_info.fpga_size = BLADERF_FPGA_UNKNOWN; diff --git a/host/utilities/bladeRF-cli/src/common.h b/host/utilities/bladeRF-cli/src/common.h index 137e34b8..bc6d410a 100644 --- a/host/utilities/bladeRF-cli/src/common.h +++ b/host/utilities/bladeRF-cli/src/common.h @@ -118,7 +118,6 @@ struct cli_state { struct rxtx_data *rx; /**< Data for sample reception */ struct rxtx_data *tx; /**< Data for sample transmission */ - bool bit_mode_8bit; /**< Bit mode is set to 16 bits */ bladerf_format sample_format; /**< Sample format */ }; From fcc6b644aad7fd935cb90d82f17650092b991527 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 4 Mar 2025 13:04:56 -0600 Subject: [PATCH 36/41] bladeRF-cli: added sc16q11 packed format support --- host/utilities/bladeRF-cli/src/cmd/printset_impl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c index 539d5fb2..38782a18 100644 --- a/host/utilities/bladeRF-cli/src/cmd/printset_impl.c +++ b/host/utilities/bladeRF-cli/src/cmd/printset_impl.c @@ -1309,6 +1309,9 @@ int print_bitmode(struct cli_state *state, int argc, char **argv) case BLADERF_FORMAT_SC16_Q11: mode_str = "16 bit"; break; + case BLADERF_FORMAT_SC16_Q11_PACKED: + mode_str = "Packed 16 bit"; + break; case BLADERF_FORMAT_SC8_Q7: mode_str = "8 bit"; break; @@ -1334,7 +1337,7 @@ int set_bitmode(struct cli_state *state, int argc, char **argv) if (argc != 3) { if (argc == 2) { - printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]); + printf(" Usage: %s %s <8|16|packed>\n", argv[0], argv[1]); rv = CLI_RET_OK; goto out; } else { @@ -1360,8 +1363,10 @@ int set_bitmode(struct cli_state *state, int argc, char **argv) } state->sample_format = BLADERF_FORMAT_SC8_Q7; + } else if (!strcasecmp("packed", argv[2])) { + state->sample_format = BLADERF_FORMAT_SC16_Q11_PACKED; } else { - printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]); + printf(" Usage: %s %s <8|16|packed>\n", argv[0], argv[1]); rv = CLI_RET_UNSUPPORTED; goto out; } From 1a1ca5c4a862d8f540569d31376bb16a67fe7691 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 2 Oct 2024 11:23:00 -0500 Subject: [PATCH 37/41] bladeRF-cli: added sc16q11 packed siso rx example --- .../bladeRF-cli/sc16q11-packed-siso/README.md | 26 ++++++++++ .../sc16q11-packed-siso/requirements.txt | 14 ++++++ .../bladeRF-cli/sc16q11-packed-siso/run.sh | 3 ++ .../bladeRF-cli/sc16q11-packed-siso/rx.txt | 7 +++ .../sc16q11-packed-siso/validate.py | 47 +++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/README.md create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/requirements.txt create mode 100755 host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/README.md b/host/examples/bladeRF-cli/sc16q11-packed-siso/README.md new file mode 100644 index 00000000..4246506a --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/README.md @@ -0,0 +1,26 @@ +# BladeRF CLI RX SISO Packed + +This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples. + +## Prerequisites + +Before running this example, ensure the Python environment is initialized and install the dependencies: + +```bash +python3 -m venv env +source env/bin/activate +pip install -r requirements.txt +``` + +## Running the Example + +To run the example, execute the following command: + +```bash +./run.sh +``` + +This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file. + +The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection. + diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/requirements.txt b/host/examples/bladeRF-cli/sc16q11-packed-siso/requirements.txt new file mode 100644 index 00000000..a5f0390e --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/requirements.txt @@ -0,0 +1,14 @@ +contourpy==1.3.0 +cycler==0.12.1 +fonttools==4.54.1 +kiwisolver==1.4.7 +matplotlib==3.9.2 +numpy==2.1.1 +packaging==24.1 +pandas==2.2.3 +pillow==10.4.0 +pyparsing==3.1.4 +python-dateutil==2.9.0.post0 +pytz==2024.2 +six==1.16.0 +tzdata==2024.2 diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh b/host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh new file mode 100755 index 00000000..a29f4495 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh @@ -0,0 +1,3 @@ +set -e +bladeRF-cli -s rx.txt +python3 validate.py /tmp/data.csv diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt b/host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt new file mode 100644 index 00000000..22036223 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt @@ -0,0 +1,7 @@ +set frequency 915M +set samplerate 20M +set rx_mux 12BIT_COUNTER +set bitmode packed +rx config file=/tmp/data.csv format=csv n=200k +rx start +rx wait diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py b/host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py new file mode 100644 index 00000000..72564195 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py @@ -0,0 +1,47 @@ +import matplotlib.pyplot as plt +import pandas as pd +import numpy as np +import sys + +def import_data(file_path): + try: + df = pd.read_csv(file_path, header=None, names=['I', 'Q']) + + if df.shape[1] < 2: + raise ValueError("CSV file must contain at least two columns for I and Q values") + + # Check if the data is numeric + if not (df['I'].dtype.kind in 'biufc' and df['Q'].dtype.kind in 'biufc'): + raise ValueError("I and Q samples must be numeric") + + return df + + except FileNotFoundError: + print(f"Error: File '{file_path}' not found") + sys.exit(1) + except pd.errors.EmptyDataError: + print(f"Error: File '{file_path}' is empty") + sys.exit(1) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) + +if len(sys.argv) != 2: + print("Usage: python validate.py ") + sys.exit(1) + +file_path = sys.argv[1] +df = import_data(file_path) + +# Plot I and Q components on the same graph +plt.figure(figsize=(10, 6)) +plt.plot(df.index, df['I'], label='I', alpha=0.7) +plt.plot(df.index, df['Q'], label='Q', alpha=0.7) +plt.xlabel('Sample Index') +plt.ylabel('Amplitude') +plt.title('I/Q Components Over Time') +plt.legend() +plt.grid(True, alpha=0.3) + +plt.tight_layout() +plt.show() From 88a110e269eb005e06de3d400b72f4978c41ab99 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 2 Oct 2024 14:05:23 -0500 Subject: [PATCH 38/41] bladeRF-cli: added sc16q11 packed mimo rx example --- .../bladeRF-cli/sc16q11-packed-mimo/README.md | 25 +++++ .../sc16q11-packed-mimo/requirements.txt | 14 +++ .../bladeRF-cli/sc16q11-packed-mimo/run.sh | 3 + .../bladeRF-cli/sc16q11-packed-mimo/rx.txt | 8 ++ .../sc16q11-packed-mimo/validate.py | 100 ++++++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/requirements.txt create mode 100755 host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md b/host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md new file mode 100644 index 00000000..dd2ba2ea --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md @@ -0,0 +1,25 @@ +# BladeRF CLI RX MIMO Packed + +This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples. + +## Prerequisites + +Before running this example, ensure the Python environment is initialized and install the dependencies: + +```bash +python3 -m venv env +source env/bin/activate +pip install -r requirements.txt +``` + +## Running the Example + +To run the example, execute the following command: + +```bash +./run.sh +``` + +This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file. + +The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection. diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/requirements.txt b/host/examples/bladeRF-cli/sc16q11-packed-mimo/requirements.txt new file mode 100644 index 00000000..a5f0390e --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/requirements.txt @@ -0,0 +1,14 @@ +contourpy==1.3.0 +cycler==0.12.1 +fonttools==4.54.1 +kiwisolver==1.4.7 +matplotlib==3.9.2 +numpy==2.1.1 +packaging==24.1 +pandas==2.2.3 +pillow==10.4.0 +pyparsing==3.1.4 +python-dateutil==2.9.0.post0 +pytz==2024.2 +six==1.16.0 +tzdata==2024.2 diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh b/host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh new file mode 100755 index 00000000..a29f4495 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh @@ -0,0 +1,3 @@ +set -e +bladeRF-cli -s rx.txt +python3 validate.py /tmp/data.csv diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt b/host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt new file mode 100644 index 00000000..18b5c1b6 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt @@ -0,0 +1,8 @@ +set bitmode packed +set rx_mux 12BIT_COUNTER +# set frequency 915M +set samplerate 61.44M +rx config file=/tmp/data.csv format=csv n=40k channel=1,2 +# rx config file=/tmp/data.csv format=csv n=200k +rx start +rx wait diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py b/host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py new file mode 100644 index 00000000..536e4355 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py @@ -0,0 +1,100 @@ +import matplotlib.pyplot as plt +import pandas as pd +import numpy as np +import sys +import ast + +def import_data(file_path): + try: + # Read the CSV file without header + df = pd.read_csv(file_path, header=None) + + # Function to safely convert string representations of tuples to actual tuples + def safe_eval(x): + try: + return ast.literal_eval(x) + except: + return x + + # Apply safe_eval to all elements + df = df.apply(lambda col: col.map(safe_eval)) + + # Rename columns based on the number of columns + if df.shape[1] == 2: + df.columns = ['I', 'Q'] + elif df.shape[1] == 4: + df.columns = ['I1', 'Q1', 'I2', 'Q2'] + else: + raise ValueError("CSV file must contain either two columns (single channel) or four columns (dual channel)") + + # Extract numeric values from tuples if necessary + for col in df.columns: + if df[col].dtype == 'object': + df[col] = df[col].apply(lambda x: x[0] if isinstance(x, (tuple, list)) else x) + + # Convert to numeric, coercing errors to NaN + df = df.apply(pd.to_numeric, errors='coerce') + + # Drop any rows with NaN values + df = df.dropna() + + # Check if all columns are numeric + for col in df.columns: + if not pd.api.types.is_numeric_dtype(df[col]): + raise ValueError(f"{col} samples must be numeric") + + return df + + except FileNotFoundError: + print(f"Error: File '{file_path}' not found") + sys.exit(1) + except pd.errors.EmptyDataError: + print(f"Error: File '{file_path}' is empty") + sys.exit(1) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) + +if len(sys.argv) != 2: + print("Usage: python validate.py ") + sys.exit(1) + +file_path = sys.argv[1] +df = import_data(file_path) + +# Determine if it's single or dual channel +is_dual_channel = 'I2' in df.columns + +plt.figure(figsize=(12, 8)) + +if is_dual_channel: + # Plot Channel 1 + plt.subplot(2, 1, 1) + plt.plot(df.index, df['I1'], label='I (Ch1)', alpha=0.7) + plt.plot(df.index, df['Q1'], label='Q (Ch1)', alpha=0.7) + plt.ylabel('Amplitude (Ch1)') + plt.title('I/Q Components Over Time - Channel 1') + plt.legend(loc='upper right') + plt.grid(True, alpha=0.3) + + # Plot Channel 2 + plt.subplot(2, 1, 2) + plt.plot(df.index, df['I2'], label='I (Ch2)', alpha=0.7) + plt.plot(df.index, df['Q2'], label='Q (Ch2)', alpha=0.7) + plt.xlabel('Sample Index') + plt.ylabel('Amplitude (Ch2)') + plt.title('I/Q Components Over Time - Channel 2') + plt.legend(loc='upper right') + plt.grid(True, alpha=0.3) +else: + # Plot Single Channel + plt.plot(df.index, df['I'], label='I', alpha=0.7) + plt.plot(df.index, df['Q'], label='Q', alpha=0.7) + plt.xlabel('Sample Index') + plt.ylabel('Amplitude') + plt.title('I/Q Components Over Time - Single Channel') + plt.legend(loc='upper right') + plt.grid(True, alpha=0.3) + +plt.tight_layout() +plt.show() From 69bf713502b3e0a428a68b73db4d19df8aeb1bd2 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 16 Oct 2024 16:59:07 -0500 Subject: [PATCH 39/41] bladeRF-cli: added sc16q11 packed siso tx example --- .../sc16q11-packed-siso/.gitignore | 1 + .../generate_tx_samples.py | 51 +++++++++++++++++++ .../bladeRF-cli/sc16q11-packed-siso/tx.txt | 6 +++ 3 files changed, 58 insertions(+) create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/generate_tx_samples.py create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore b/host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore new file mode 100644 index 00000000..1e569eb6 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore @@ -0,0 +1 @@ +tx_samples.csv diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/generate_tx_samples.py b/host/examples/bladeRF-cli/sc16q11-packed-siso/generate_tx_samples.py new file mode 100644 index 00000000..7612ce9d --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/generate_tx_samples.py @@ -0,0 +1,51 @@ +import csv +import sys + +def generate_csv_normal(filename): + with open(filename, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + + # Generate numbers from 0 to 2047 + for i in range(0, 2048, 2): + writer.writerow([i, i+1]) + + # Generate numbers from -2048 to -1 + for i in range(-2048, 0, 2): + writer.writerow([i, i+1]) + +def generate_csv_cw(filename): + cw_pattern = [ + [0, 2047], + [2047, 0], + [0, -2047], + [-2047, 0] + ] + + with open(filename, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + for _ in range(2*4096): + for sample in cw_pattern: + # Duplicate the pattern for both channels + writer.writerow(sample) + +if __name__ == "__main__": + filename = 'tx_samples.csv' + + if len(sys.argv) > 1: + if sys.argv[1] == "-h" or sys.argv[1] == "--help": + print("Usage: python generate_tx_samples.py [option]") + print("Options:") + print(" -h, --help Show this help message and exit") + print(" cw Generate CSV file with CW pattern") + print(" (no option) Generate CSV file with count pattern") + sys.exit(0) + elif sys.argv[1] == "cw": + generate_csv_cw(filename) + print(f"CSV file '{filename}' has been generated with CW pattern.") + else: + print(f"Unknown option: {sys.argv[1]}") + print("Use -h or --help for usage information.") + sys.exit(1) + else: + generate_csv_normal(filename) + print(f"CSV file '{filename}' has been generated with count pattern.") diff --git a/host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt b/host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt new file mode 100644 index 00000000..f32a2a3e --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt @@ -0,0 +1,6 @@ +set frequency 915M +set samplerate 20M +set bitmode packed +tx config file=tx_samples.csv format=csv +tx start +tx wait From 6364f25b3648bfd4b1e2e35d55c0e20bd3077ea8 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 16 Oct 2024 17:04:08 -0500 Subject: [PATCH 40/41] bladeRF-cli: added sc16q11 packed mimo tx example --- .../sc16q11-packed-mimo/.gitignore | 1 + .../generate_tx_samples.py | 51 +++++++++++++++++++ .../bladeRF-cli/sc16q11-packed-mimo/tx.txt | 6 +++ 3 files changed, 58 insertions(+) create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/generate_tx_samples.py create mode 100644 host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore b/host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore new file mode 100644 index 00000000..1e569eb6 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore @@ -0,0 +1 @@ +tx_samples.csv diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/generate_tx_samples.py b/host/examples/bladeRF-cli/sc16q11-packed-mimo/generate_tx_samples.py new file mode 100644 index 00000000..b6322555 --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/generate_tx_samples.py @@ -0,0 +1,51 @@ +import csv +import sys + +def generate_csv_normal(filename): + with open(filename, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + + # Generate numbers from 0 to 2047 + for i in range(0, 2048, 4): + writer.writerow([i, i+1, i+2, i+3]) + + # Generate numbers from -2048 to -1 + for i in range(-2048, 0, 4): + writer.writerow([i, i+1, i+2, i+3]) + +def generate_csv_cw(filename): + cw_pattern = [ + [0, 2047], + [2047, 0], + [0, -2047], + [-2047, 0] + ] + + with open(filename, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + for _ in range(2*4096): + for sample in cw_pattern: + # Duplicate the pattern for both channels + writer.writerow(sample + sample) + +if __name__ == "__main__": + filename = 'tx_samples.csv' + + if len(sys.argv) > 1: + if sys.argv[1] == "-h" or sys.argv[1] == "--help": + print("Usage: python generate_tx_samples.py [option]") + print("Options:") + print(" -h, --help Show this help message and exit") + print(" cw Generate CSV file with CW pattern") + print(" (no option) Generate CSV file with count pattern") + sys.exit(0) + elif sys.argv[1] == "cw": + generate_csv_cw(filename) + print(f"CSV file '{filename}' has been generated with CW pattern.") + else: + print(f"Unknown option: {sys.argv[1]}") + print("Use -h or --help for usage information.") + sys.exit(1) + else: + generate_csv_normal(filename) + print(f"CSV file '{filename}' has been generated with count pattern.") diff --git a/host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt b/host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt new file mode 100644 index 00000000..0ec94c7c --- /dev/null +++ b/host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt @@ -0,0 +1,6 @@ +set frequency 915M +set samplerate 20M +set bitmode packed +tx config file=tx_samples.csv format=csv channel=1,2 +tx start +tx wait From 13a573508d8f6b87ed23c94471b515e4a133034a Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Tue, 8 Oct 2024 15:39:54 -0500 Subject: [PATCH 41/41] test: added fx3_gpif_iq_packed_tb to regression test --- host/libraries/libbladeRF_test/test_regression/src/main.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/host/libraries/libbladeRF_test/test_regression/src/main.cxx b/host/libraries/libbladeRF_test/test_regression/src/main.cxx index 6b3bad0c..3d95ba07 100644 --- a/host/libraries/libbladeRF_test/test_regression/src/main.cxx +++ b/host/libraries/libbladeRF_test/test_regression/src/main.cxx @@ -337,6 +337,7 @@ INSTANTIATE_TEST_SUITE_P(hdl, verify, TEST_HDL_COMPILE(compile) TEST_HDL_COMPILE(fx3_gpif_iq_tb) +TEST_HDL_COMPILE(fx3_gpif_iq_packed_tb) TEST_HDL_COMPILE(fx3_gpif_iq_8bit_tb) TEST_HDL_COMPILE(fx3_gpif_meta_8bit_tb) TEST_HDL_COMPILE(fx3_gpif_meta_tb) @@ -351,6 +352,10 @@ TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1 TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000); TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b11, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='1', 1000); +TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='1', 1000); +TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000); +TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b11, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='1', 1000); + TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b00, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='0', 1000); TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='1', 1000); TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000);