### Setup Environment Script for USRP3 Simulation Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/sim/running_testbenches.md Example of sourcing the setup environment script for a specific USRP product, which is necessary before running simulations. ```bash $ source /fpga/usrp3/top//setupenv.sh ``` -------------------------------- ### UHD_INSTALL Command Example Source: https://github.com/ettusresearch/uhd/blob/master/host/include/uhd/utils/CMakeLists.txt Example of using the UHD_INSTALL macro to install header files into the uhd/utils directory. ```cmake UHD_INSTALL( FILES algorithm.hpp assert_has.hpp assert_has.ipp byteswap.hpp byteswap.ipp cast.hpp compat_check.hpp csv.hpp dirty_tracked.hpp fp_compare_delta.ipp fp_compare_epsilon.ipp gain_group.hpp graph_utils.hpp interpolation.hpp log.hpp log_add.hpp math.hpp msg_task.hpp noncopyable.hpp paths.hpp pimpl.hpp platform.hpp pybind_adaptors.hpp safe_call.hpp safe_main.hpp scope_exit.hpp static.hpp tasks.hpp thread_priority.hpp thread.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uhd/utils COMPONENT headers ) ``` -------------------------------- ### ModelSim/Questa Setup Environment Script with Path Argument Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/sim/running_testbenches.md Example of sourcing the setup environment script with a custom path for ModelSim if it's not found automatically. ```bash $ source /fpga/usrp3/top//setupenv.sh --modelsim-path=/path/to/modelsim ``` -------------------------------- ### Install Header Files Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/rfnoc-gain/include/rfnoc/gain/CMakeLists.txt This snippet shows how to install header files for the rfnoc-gain block using CMake. ```cmake # # Copyright 2019 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # # List all header files here install( FILES config.hpp gain_block_control.hpp DESTINATION include/rfnoc/gain COMPONENT headers ) ``` -------------------------------- ### C API Examples Build Configuration Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/CMakeLists.txt This section configures the build for examples using the C API. It checks for C99 struct declaration support, includes a 'getopt' subdirectory, defines C API example sources, adds them as executables, links them with UHD and getopt, and installs them. ```cmake if(ENABLE_C_API) # # Check if this particular C99 feature is available with this compiler # include(CheckCSourceCompiles) CHECK_C_SOURCE_COMPILES("\n typedef struct {\n int bar;\n int baz;\n } foo;\n\n int main()\n {\n foo wat = {\n .bar = 1,\n .baz = 2\n };\n\n return 0;\n }\n " HAVE_C99_STRUCTDECL) if(HAVE_C99_STRUCTDECL) add_subdirectory(getopt) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/getopt) set(C_API_EXAMPLES rx_samples_c tx_samples_c ) foreach(example ${C_API_EXAMPLES}) add_executable(${example} ${example}.c) target_link_libraries(${example} uhd getopt) if(UNIX) target_link_libraries(${example} m) endif(UNIX) UHD_INSTALL(TARGETS ${example} RUNTIME DESTINATION ${PKG_LIB_DIR}/examples COMPONENT examples) endforeach(example ${C_API_EXAMPLES}) endif(HAVE_C99_STRUCTDECL) endif(ENABLE_C_API) ``` -------------------------------- ### Installation Commands Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/extension_example/CMakeLists.txt Defines installation rules for the extension library, handling different behaviors for UNIX and other OS. ```cmake if(UNIX) # On Linux OS install into folder and symlink to UHD_MODULE_PATH set(extension_target ${CMAKE_INSTALL_PREFIX}/lib/libextexample.so) install(TARGETS extexample DESTINATION lib) install(CODE "execute_process(COMMAND bash -c \"mkdir -p ${UHD_MODULE_PATH} && ln -s -f ${extension_target} -t ${UHD_MODULE_PATH}\")") else(UNIX) # on other OS (Windows) install into UHD_MODULE_PATH install(TARGETS extexample DESTINATION ${UHD_MODULE_PATH}) endif(UNIX) ``` -------------------------------- ### Example Applications Build Configuration Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/CMakeLists.txt This section defines a list of C++ source files for example applications, adds them as executables, links them with necessary libraries (UHD, Boost), and installs them. ```cmake #for each source: build an executable and install foreach(example_source ${example_sources}) get_filename_component(example_name ${example_source} NAME_WE) add_executable(${example_name} ${example_source}) target_link_libraries(${example_name} PUBLIC uhd Boost::program_options Boost::filesystem) UHD_INSTALL(TARGETS ${example_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/examples COMPONENT examples) endforeach(example_source) ``` -------------------------------- ### Example Testbench Makefile Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/sim/writing_sim_makefile.md A sample Makefile for a UHD FPGA testbench, demonstrating the structure and common variables used for simulation setup. ```makefile # # Copyright 2020 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: LGPL-3.0-or-later # #------------------------------------------------- # Top-of-Makefile #------------------------------------------------- # Define BASE_DIR to point to the "top" dir. Note: # UHD_FPGA_DIR must be passed into this Makefile. ifndef UHD_FPGA_DIR $(error "UHD_FPGA_DIR is not set! Must point to UHD FPGA repository!") endif BASE_DIR = $(UHD_FPGA_DIR)/usrp3/top # Include viv_sim_preamble after defining BASE_DIR include $(BASE_DIR)/../tools/make/viv_sim_preamble.mak #------------------------------------------------- # Design Specific #------------------------------------------------- # Define part using PART_ID (//) ARCH = kintex7 PART_ID = xc7k410t/ffg900/-2 # Include makefiles and sources for the DUT and its dependencies include $(BASE_DIR)/../lib/rfnoc/core/Makefile.srcs include $(BASE_DIR)/../lib/rfnoc/utils/Makefile.srcs include $(BASE_DIR)/../lib/fifo/Makefile.srcs include $(BASE_DIR)/../lib/axi/Makefile.srcs include $(BASE_DIR)/../lib/control/Makefile.srcs DESIGN_SRCS += $(abspath \ $(RFNOC_CORE_SRCS) \ $(RFNOC_UTIL_SRCS) \ $(RFNOC_OOT_SRCS) \ $(FIFO_SRCS) \ $(AXI_SRCS) \ $(CONTROL_LIB_SRCS) \ ) #------------------------------------------------- # IP Specific #------------------------------------------------- # If simulation contains IP, define the IP_DIR and point # it to the base level IP directory IP_DIR = $(BASE_DIR)/x300/ip LIB_IP_DIR = $(BASE_DIR)/../lib/ip # Include makefiles and sources for all IP components # *after* defining the IP_DIR include $(IP_DIR)/fifo_4k_2clk/Makefile.inc include $(LIB_IP_DIR)/axi_fft/Makefile.inc DESIGN_SRCS += $(abspath \ $(IP_FIFO_4K_2CLK_SRCS) \ $(LIB_IP_AXI_FFT_SRCS) \ rfnoc_block_example.v \ ) #------------------------------------------------- # Testbench Specific #------------------------------------------------- include $(BASE_DIR)/../sim/general/Makefile.srcs include $(BASE_DIR)/../sim/axi/Makefile.srcs # Define only one top-level module SIM_TOP = rfnoc_block_example_tb # Simulation runtime in microseconds SIM_RUNTIME_US = 1000 SIM_SRCS = \ $(abspath rfnoc_block_example_tb.sv) \ #------------------------------------------------- # Bottom-of-Makefile #------------------------------------------------- # Include all simulator specific makefiles here # Each should define a unique target to simulate # e.g. xsim, vsim, etc and a common "clean" target include $(BASE_DIR)/../tools/make/viv_simulator.mak ``` -------------------------------- ### Source setup script with custom ModelSim/Questa path Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/sim/running_testbenches.md If ModelSim or Questa is installed in a non-default location, run the following: ```bash $ source /fpga/usrp3/top//setupenv.sh --modelsim-path= ``` -------------------------------- ### Python Example List Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/python/CMakeLists.txt This variable lists the Python example scripts that will be installed. ```cmake set(python_examples rfnoc_rx_replay_samples_to_file.py rx_to_file.py tx_waveforms.py rx_spectrum_to_asciiplot.py benchmark_rate.py usrp_power_meter.py rx_to_remote_udp.py rfnoc_rx_to_file.py x440_L_band_capture.py rfnoc_txrx_fft_block_loopback.py rx_spectrum_to_pyplot.py ) UHD_INSTALL(PROGRAMS ${python_examples} DESTINATION ${PKG_LIB_DIR}/examples/python COMPONENT examples) ``` -------------------------------- ### Server Example Source: https://github.com/ettusresearch/uhd/blob/master/host/lib/deps/rpclib/README.md This C++ code demonstrates how to set up an rpclib server, bind functions (free function and lambda), and run the server loop. ```cpp #include #include "rpc/server.h" void foo() { std::cout << "foo was called!" << std::endl; } int main(int argc, char *argv[]) { // Creating a server that listens on port 8080 rpc::server srv(8080); // Binding the name "foo" to free function foo. // note: the signature is automatically captured srv.bind("foo", &foo); // Binding a lambda function to the name "add". srv.bind("add", [](int a, int b) { return a + b; }); // Run the server loop. srv.run(); return 0; } ``` -------------------------------- ### Example build command with an additional option Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/build_instructions.md Example of making a target and specifying additional options in the form VAR=VALUE. ```bash $ make X310 GUI=1 ``` -------------------------------- ### CMakeLists.txt Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/rfnoc-gain/examples/CMakeLists.txt This snippet shows the CMake configuration for the rfnoc-gain example, including setting source files and installation destinations. ```cmake # # Copyright 2024 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # set(examples_sources_py rx_gain_estimate_power.py ) # TODO: Properly shebang the Python files depending on platform install( FILES ${examples_sources_py} DESTINATION ${UHD_PKG_DATA_DIR}/examples/rfnoc-gain COMPONENT examples ) ``` -------------------------------- ### Source environment setup script Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/build_instructions.md Sources the environment setup script to enable direct use of make targets. ```bash source ./setupenv.sh ``` -------------------------------- ### Project Setup and Version Handling Source: https://github.com/ettusresearch/uhd/blob/master/host/CMakeLists.txt Sets up the main project, handling custom UHD_VERSION definitions and restoring them after the project() command. ```cmake # Backup custom UHD_VERSION if defined by using option -DUHD_VERSION=..., # because project() will reset it to an empty string. if(UHD_VERSION) set(CUSTOM_UHD_VERSION "${UHD_VERSION}") endif(UHD_VERSION) # Note: if UHD_VERSION is not defined, project() will leave it undefined # for cmake version < 4.1.0, but set it to an empty string for cmake # version >= 4.1.0. project(UHD CXX C) # Restore the custom UHD_VERSION if it was defined before project() if(DEFINED CUSTOM_UHD_VERSION) set(UHD_VERSION "${CUSTOM_UHD_VERSION}" CACHE STRING "" FORCE) endif(DEFINED CUSTOM_UHD_VERSION) ``` -------------------------------- ### CMakeLists.txt Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/extension_example/lib/CMakeLists.txt The CMakeLists.txt file for the extension_example, including copyright and license information, and setting a variable. ```cmake # # Copyright 2022 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # ######################################################################## # This file included, use CMake directory variables ######################################################################## set(extension_example "" PARENT_SCOPE) message(STATUS ${extension_example_sources}) ``` -------------------------------- ### Installation Source: https://github.com/ettusresearch/uhd/blob/master/firmware/usrp3/x300/CMakeLists.txt Installs the compiled firmware binary to the appropriate location. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/x300_main.bin DESTINATION share/uhd/images RENAME usrp_x300_fw.bin ) ``` -------------------------------- ### CMakeLists.txt Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/rfnoc-gain/rfnoc/blocks/CMakeLists.txt This CMakeLists.txt file is used to install block descriptor files for the rfnoc-gain example. ```cmake # # Copyright 2019 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # # Reminder: This won't auto-update when you add a file, you need to re-run CMake # to re-generate the glob. Or, you add the files directly into the install() # statement below. file(GLOB yml_files "*.yml") # List all block descriptor files here: install( FILES ${yml_files} DESTINATION ${RFNOC_PKG_DATA_DIR}/blocks COMPONENT blocks ) ``` -------------------------------- ### Xilinx ISE Make Options Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/build_instructions.md Options for Xilinx ISE builds. ```bash PROJECT_ONLY=1 : Only create a Xilinx project for the specified target(s). Useful for use with the ISE GUI. EXPORT_ONLY=1 : Export build targets from a GUI build to the build directory. Requires the project in build-*_* to be built. ``` -------------------------------- ### Workflow for building bitfiles after installation Source: https://github.com/ettusresearch/uhd/blob/master/host/examples/rfnoc-gain/README.md Demonstrates a workflow for building bitfiles using installed files, including configuring the project, building with and without the -I flag. ```shell cd /path/to/rfnoc-gain # Switch to this file's directory mkdir build && cd build && cmake .. -DUHD_FPGA_DIR=/path/to/uhd/fpga # Configure the project # Now, launch an image build and use all files from this directory: rfnoc_image_builder -y ../icores/x310_rfnoc_image_core.yml -I ../rfnoc make install # Install software and gateware # Build again, without -I: rfnoc_image_builder -y ../icores/x310_rfnoc_image_core.yml ``` -------------------------------- ### Build simulation libraries with help Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/sim/running_testbenches.md For other options, run: ```bash $ build_simlibs --help ``` -------------------------------- ### Default Gain Profile Example Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/devices/zbx.dox Demonstrates setting and getting the TX gain in the 'default' gain profile. ```cpp // Assumption: 'usrp' is a multi_usrp object usrp->set_tx_gain_profile("default"); // Only necessary if the gain profile was set to something else before usrp->set_tx_gain(30); // Will set the gain to 30 dB on all associated daughterboards std::cout << usrp->get_tx_gain() << std::endl; // Should print "30" usrp->set_tx_gain(0, "DSA1"); // Will cause an exception // Individual DSAs may still be queried. Note that even though this is an // attenuator, the return value is a gain (higher values mean more TX power): auto dsa1_gain = usrp->get_tx_gain("DSA1"); ``` -------------------------------- ### Verify USRP Setup Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/devices/usrp_x4xx.dox This command probes the USRP device to ensure proper installation, network connectivity, and operation. ```bash uhd_usrp_probe --args "addr=" ``` -------------------------------- ### Xilinx Vivado Make Options Source: https://github.com/ettusresearch/uhd/blob/master/host/docs/fpga/usrp3/build_instructions.md Options for Xilinx Vivado builds. ```bash GUI=1 : Run the Vivado build in GUI mode instead of batch mode. After the build is complete, Vivado provides an option to save the fully configured project for customization CHECK=1 : Run elaboration only to check HDL syntax SYNTH=1 : Run synthesis only TOP= : Specify an alternate top-level module for syntax checking ``` -------------------------------- ### Configure setup.py and pyproject.toml Source: https://github.com/ettusresearch/uhd/blob/master/host/python/CMakeLists.txt Configures the setup.py file and pyproject.toml (on Windows) using input templates and the current binary directory. ```cmake # convert binary directory to native format to use in SETUP_PY file. file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} NATIVE_CURRENT_BINARY_DIR) configure_file(${SETUP_PY_IN} ${SETUP_PY}) if(WIN32) configure_file(${PYPROJECT_TOML_IN} ${PYPROJECT_TOML}) endif(WIN32) ```