diff options
author | Martin Braun <martin.braun@ettus.com> | 2024-04-02 12:23:02 +0200 |
---|---|---|
committer | joergho <48011876+joergho@users.noreply.github.com> | 2024-04-02 16:27:20 +0200 |
commit | 395086a60528176f02e338f5d64c583eac7f1f3b (patch) | |
tree | 836d750c253e0c01aa11177ff3f80286c5464693 | |
parent | lib: adf5356: Fix FRAC2 calculation (diff) | |
download | uhd-395086a60528176f02e338f5d64c583eac7f1f3b.tar.xz uhd-395086a60528176f02e338f5d64c583eac7f1f3b.zip |
tests: Add unit test for ADF535x PLLs
-rw-r--r-- | host/tests/CMakeLists.txt | 8 | ||||
-rw-r--r-- | host/tests/adf535x_test.cpp | 98 |
2 files changed, 106 insertions, 0 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 014b42c91..29eb1e219 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -296,6 +296,14 @@ UHD_ADD_NONAPI_TEST( ${UHD_BINARY_DIR}/lib/ic_reg_maps ) +UHD_ADD_NONAPI_TEST( + TARGET adf535x_test.cpp + EXTRA_SOURCES + ${UHD_SOURCE_DIR}/lib/usrp/common/adf535x.cpp + INCLUDE_DIRS + ${UHD_BINARY_DIR}/lib/ic_reg_maps +) + set_source_files_properties( ${UHD_SOURCE_DIR}/lib/utils/system_time.cpp PROPERTIES COMPILE_DEFINITIONS diff --git a/host/tests/adf535x_test.cpp b/host/tests/adf535x_test.cpp new file mode 100644 index 000000000..eebec8bbe --- /dev/null +++ b/host/tests/adf535x_test.cpp @@ -0,0 +1,98 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include "adf5355_regs.hpp" +#include "adf5356_regs.hpp" +#include <uhd/utils/log.hpp> +#include <uhdlib/usrp/common/adf535x.hpp> +#include <uhdlib/utils/narrow.hpp> +#include <boost/test/unit_test.hpp> +#include <map> + + +template <typename adf535x_regs_t> +class adf535x_mem +{ +public: + adf535x_mem() + { + // Copy chip defaults into mem + for (uint8_t addr = 0; addr < 13; addr++) { + mem[addr] = regs.get_reg(addr); + } + } + + void poke32(const uint8_t addr, const uint32_t data) + { + UHD_LOG_INFO("ADF535x", + "W[" << boost::format("%02d") % static_cast<int>(addr) << "] => " + << boost::format("%08X") % data); + mem[addr] = data; + } + + adf535x_regs_t regs; + std::map<uint8_t, uint16_t> mem; +}; + + +BOOST_AUTO_TEST_CASE(adf5355_init_test) +{ + auto mem = adf535x_mem<adf5355_regs_t>{}; + UHD_LOG_INFO("ADF535x", "Initializing ADF5355..."); + auto lo = adf535x_iface::make_adf5355( + [&](const std::vector<uint32_t> regs) { + for (auto& reg : regs) { + mem.poke32(uhd::narrow_cast<uint8_t>(reg & 0xF), reg); + } + }, + [&](const uint32_t wait_time_us) { + std::cout << "Waiting " << wait_time_us << "us..." << std::endl; + }); + lo->commit(); + UHD_LOG_INFO("ADF535x", "De-initializing ADF5355..."); +} + +BOOST_AUTO_TEST_CASE(adf5356_init_test) +{ + auto mem = adf535x_mem<adf5356_regs_t>{}; + UHD_LOG_INFO("ADF535x", "Initializing ADF5356..."); + auto lo = adf535x_iface::make_adf5356( + [&](const std::vector<uint32_t> regs) { + for (auto& reg : regs) { + mem.poke32(uhd::narrow_cast<uint8_t>(reg & 0xF), reg); + } + }, + [&](const uint32_t wait_time_us) { + std::cout << "Waiting " << wait_time_us << "us..." << std::endl; + }); + lo->commit(); + UHD_LOG_INFO("ADF535x", "De-initializing ADF5356..."); +} + +BOOST_AUTO_TEST_CASE(adf5356_test_freqs) +{ + auto mem = adf535x_mem<adf5356_regs_t>{}; + auto lo = adf535x_iface::make_adf5356( + [&](const std::vector<uint32_t> regs) { + for (auto& reg : regs) { + mem.poke32(uhd::narrow_cast<uint8_t>(reg & 0xF), reg); + } + }, + [&](const uint32_t wait_time_us) { + std::cout << "Waiting " << wait_time_us << "us..." << std::endl; + }); + lo->commit(); + // Use TwinRX RevC settings here (LO1 is ADF5355 for lower revs, and ADF5356 + // for RevC and beyond). + lo->set_pfd_freq(12.5e6); + lo->set_output_power(adf535x_iface::OUTPUT_POWER_5DBM); + lo->set_reference_freq(100e6); + lo->set_muxout_mode(adf535x_iface::MUXOUT_DLD); + + for (double f = 2.0e9; f < 6.8e9; f += 10e6) { + lo->set_frequency(f, 2, false); + } +} |