aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/dboard/db_rfx.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-11-22 12:01:19 -0800
committerMartin Braun <martin.braun@ettus.com>2019-11-22 21:13:58 -0800
commit67a96646d03a9732b46bcd53983c4279ae896a70 (patch)
treef730d6338358281fe4f2e967fbd5bd8b44d58d78 /host/lib/usrp/dboard/db_rfx.cpp
parent1996adfc49fa858510c9c77cde761c0460378775 (diff)
downloaduhd-67a96646d03a9732b46bcd53983c4279ae896a70.tar.gz
uhd-67a96646d03a9732b46bcd53983c4279ae896a70.tar.bz2
uhd-67a96646d03a9732b46bcd53983c4279ae896a70.zip
rfx: Fix calculation of prescaler and band select
The code was broken when converting from BOOST_FOREACH to a range-based for loop. Without this fix, the board initialization would crash with an error like this: [ERROR] [DBMGR] The daughterboard manager encountered a recoverable error in init. Loading the "unknown" daughterboard implementations to continue. The daughterboard cannot operate until this error is resolved. LookupError: KeyError: key "0" not found in dict(i, N14adf4360_regs_t17prescaler_value_tE)
Diffstat (limited to 'host/lib/usrp/dboard/db_rfx.cpp')
-rw-r--r--host/lib/usrp/dboard/db_rfx.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp
index b47d0fded..f530458ff 100644
--- a/host/lib/usrp/dboard/db_rfx.cpp
+++ b/host/lib/usrp/dboard/db_rfx.cpp
@@ -359,7 +359,7 @@ double rfx_xcvr::set_lo_freq(
int R=0, BS=0, P=0, B=0, A=0;
/*
- * The goal here to to loop though possible R dividers,
+ * The goal here to to loop through possible R dividers,
* band select clock dividers, and prescaler values.
* Calculate the A and B counters for each set of values.
* The loop exits when it meets all of the constraints.
@@ -368,23 +368,30 @@ double rfx_xcvr::set_lo_freq(
* fvco = [P*B + A] * fref/R
* fvco*R/fref = P*B + A = N
*/
- for(R = 2; R <= 32; R+=2){
- for(auto BS: bandsel_to_enum.keys()){
- if (ref_freq/R/BS > 1e6) continue; //constraint on band select clock
- for(auto P: prescaler_to_enum.keys()){
- //calculate B and A from N
- double N = target_freq*R/ref_freq;
- B = int(std::floor(N/P));
- A = boost::math::iround(N - P*B);
- if (B < A or B > 8191 or B < 3 or A > 31) continue; //constraints on A, B
- //calculate the actual frequency
- actual_freq = double(P*B + A)*ref_freq/R;
- if (actual_freq/P > 300e6) continue; //constraint on prescaler output
- //constraints met: exit loop
+ for (R = 2; R <= 32; R += 2) { // Search through all valid R values
+ for (BS = 1; BS <= 8; BS *= 2) { // Search through all valid band selects
+ if (ref_freq / R / BS > 1e6) {
+ continue; // constraint on band select clock
+ }
+ for (P = 8; P <= 32; P *= 2) { // Search through all prescaler values
+ // calculate B and A from N
+ double N = target_freq * R / ref_freq;
+ B = int(std::floor(N / P));
+ A = boost::math::iround(N - P * B);
+ if (B < A or B > 8191 or B < 3 or A > 31) {
+ continue; // constraints on A, B
+ }
+ // calculate the actual frequency
+ actual_freq = double(P * B + A) * ref_freq / R;
+ if (actual_freq / P > 300e6) {
+ continue; // constraint on prescaler output
+ }
+ // constraints met: exit loop
goto done_loop;
}
}
- } done_loop:
+ }
+done_loop:
UHD_LOGGER_TRACE("RFX") << boost::format(
"RFX tune: R=%d, BS=%d, P=%d, B=%d, A=%d, DIV2=%d"