From 3a2d07062bdde25fee361e167e2b5b2675ab5f11 Mon Sep 17 00:00:00 2001 From: Tom Eichlersmith Date: Wed, 6 Apr 2022 16:06:35 -0500 Subject: [PATCH] expand elink_relink to more delay values, controlable by user --- include/pflib/PolarfireTarget.h | 28 ++++++++++++++++-- src/pflib/PolarfireTarget.cxx | 51 ++++++++++++++------------------- tool/pftool.cc | 7 +++-- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/pflib/PolarfireTarget.h b/include/pflib/PolarfireTarget.h index b446b625..5f862c5a 100644 --- a/include/pflib/PolarfireTarget.h +++ b/include/pflib/PolarfireTarget.h @@ -226,11 +226,33 @@ struct PolarfireTarget { bool loadBiasSettings(const std::string& file_name); /** Carries out the standard elink alignment process */ - void elink_relink(int ilink,int verbosity); + void elink_relink(int ilink,int min_delay = 0, int max_delay = 128); - void delay_loop(int ilink); + /** + * Go from min_delay up to max_delay stopping only if alignment is achieved + * + * Using bitslip_loop to test each delay value. + * + * @param[in] ilink link index to test + * @param[in] min_delay minimum value of delay parameter + * @param[in] max_delay maximum value of delay parameter + */ + void delay_loop(int ilink, int min_delay, int max_delay); - bool bitslip_loop(int ilink); + /** + * check all bitslip values and find the one with + * the most correct idle patterns + * + * each spy returns 60 bytes (or 15 4-byte words), + * the idle pattern is 0x9c or 0xac followed by three 0xcc. + * + * @param[in] ilink link index to loop over + * @param[out] best_slip set to best bitslip value + * @param[out] best_count set to number of idles that were correct for the best slip + * @return true if best slip value is perfect (i.e. link is aligned) + * (all possible words were corect pattern) + */ + bool bitslip_loop(int ilink, int& best_slip, int& best_count); private: int samples_per_event_; diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index fb390c14..0db00de6 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -462,41 +462,41 @@ bool PolarfireTarget::loadBiasSettings(const std::string& file_name) { } } -void PolarfireTarget::elink_relink(int ilink ,int verbosity) { +void PolarfireTarget::elink_relink(int ilink, int min_delay, int max_delay) { pflib::Elinks& elinks=hcal.elinks(); - if (ilink == -1){ for (int ilink=0; ilink spy=elinks.spy(ilink); for (size_t i=0; i+4okcount[imax]) imax=slip; - } - elinks.setBitslip(ilink,imax); - printf(" Link %d bitslip %d (ok count=%d)\n",ilink,imax,okcount[imax]); - - if (okcount[imax] == 75){ - return true; + if (best_slip<0 || okcount[slip]>okcount[best_slip]) best_slip=slip; } - else return false; - + elinks.setBitslip(ilink,best_slip); + count = okcount[best_slip]; + return (count == 15*total_cycles); } - -//} - - } // namespace pflib diff --git a/tool/pftool.cc b/tool/pftool.cc index 7a69622b..ce4e9ee4 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -225,7 +225,7 @@ static void link( const std::string& cmd, PolarfireTarget* pft ) { * pflib::Hcal::elinks and then procede to the commands. * * ## Commands - * - RELINK : pflib::PolarfireTarget::elink_relink with verbosity 2 + * - RELINK : pflib::PolarfireTarget::elink_relink * - SPY : pflib::Elinks::spy * - BITSLIP : pflib::Elinks::setBitslip and pflib::Elinks::setBitslipAuto * - BIGSPY : PolarfireTarget::elinksBigSpy @@ -240,9 +240,12 @@ static void link( const std::string& cmd, PolarfireTarget* pft ) { static void elinks( const std::string& cmd, PolarfireTarget* pft ) { pflib::Elinks& elinks=pft->hcal.elinks(); static int ilink=0; + static int min_delay{0}, max_delay{128}; if (cmd=="RELINK"){ ilink=BaseMenu::readline_int("Which elink? (-1 for all) ",ilink); - pft->elink_relink(ilink,2); + min_delay=BaseMenu::readline_int("Min delay? ",min_delay); + max_delay=BaseMenu::readline_int("Max delay? ",max_delay); + pft->elink_relink(ilink,min_delay,max_delay); } if (cmd=="SPY") { ilink=BaseMenu::readline_int("Which elink? ",ilink);