From 23930e7467ce7069d37a56e82d066e01d2e90942 Mon Sep 17 00:00:00 2001 From: Sergey Musikhin <musihin_sergei@mail.ru> Date: Thu, 10 Jun 2021 06:40:06 +0000 Subject: [PATCH] init refclk --- lib/bladerf/bladerf_common.cc | 40 +++++++++++++++++++++++++++++++++++ lib/bladerf/bladerf_common.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index ed9a8f2..244d83d 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -281,6 +281,15 @@ void bladerf_common::init(dict_t const &dict, bladerf_direction direction) } } + if(dict.count("ref_clk")) + { + auto freq = boost::lexical_cast<int>(_get(dict,"ref_clk")); + if(freq) + { + init_refclk(freq); + } + } + /* Show some info about the device we've opened */ print_device_info(); @@ -421,6 +430,37 @@ size_t bladerf_common::get_max_channels(bladerf_direction direction) #endif } +void bladerf_common::init_refclk(int freq) +{ + const bladerf_range * range = nullptr; + auto status = bladerf_get_pll_refclk_range(_dev.get(),&range); + if (status != 0) { + BLADERF_WARNING("bladerf_get_pll_refclk_range: " + << bladerf_strerror(status)); + } + if (freq < range->min || freq > range->max) + { + BLADERF_WARNING(freq <<" not in ref_clk range(" + << range->min << " - "<< range->max <<")"); + } + else + { + status = bladerf_set_pll_enable(_dev.get(), true); + if (status != 0) { + BLADERF_WARNING("bladerf_set_pll_enable: " + << bladerf_strerror(status)); + } + else + { + status = bladerf_set_pll_refclk(_dev.get(), freq); + if (status != 0) { + BLADERF_WARNING("bladerf_set_pll_refclk: " + << bladerf_strerror(status)); + } + } + } +} + void bladerf_common::set_channel_enable(bladerf_channel ch, bool enable) { _enables[ch] = enable; diff --git a/lib/bladerf/bladerf_common.h b/lib/bladerf/bladerf_common.h index 4ed1c43..eca363c 100644 --- a/lib/bladerf/bladerf_common.h +++ b/lib/bladerf/bladerf_common.h @@ -163,6 +163,8 @@ protected: /* Get the maximum number of channels supported in a given direction */ size_t get_max_channels(bladerf_direction direction); + void init_refclk(int freq); + void set_channel_enable(bladerf_channel ch, bool enable); bool get_channel_enable(bladerf_channel ch); -- GitLab