From 486d61d97b6b5e7b687d21ba618280778c9e6110 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Tue, 29 Mar 2022 05:07:42 -0500 Subject: [PATCH 01/37] Add External readout mode --- src/pflib/PolarfireTarget.cxx | 4 +- tool/pftool.cc | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index 764828c7..5a365283 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -243,12 +243,14 @@ void PolarfireTarget::prepareNewRun() { auto& daq = hcal.daq(); backend->fc_bufferclear(); backend->daq_reset(); + backend->fc_clear_run(); bool enable; int extra_samples; hcal.fc().getMultisampleSetup(enable,extra_samples); samples_per_event_=extra_samples+1; + daq.enable(true); } @@ -288,7 +290,7 @@ void PolarfireTarget::daqStatus(std::ostream& os) { os << "-----Off-detector FIFO-----\n"; backend->daq_status(full, empty, events,asize); - os << " " << std::setw(8) << (full ? "FULL" : "NOT-FULL") + os << " " << std::setfill(' ') << std::setw(8) << (full ? "FULL" : "NOT-FULL") << " " << std::setw(9) << (empty ? "EMPTY" : "NOT_EMPTY") << " Events ready: " << std::setw(3) << events << " Next event size: " << asize diff --git a/tool/pftool.cc b/tool/pftool.cc index d0b282cb..19ca5ff4 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -622,6 +622,9 @@ static void daq_setup( const std::string& cmd, PolarfireTarget* pft ) { } } + +static std::string last_run_file=".last_run_file"; + /** * DAQ menu commands, DOES NOT include sub-menu commands * @@ -685,6 +688,68 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { fclose(f); } } + if (cmd=="EXTERNAL") { + int run=0; + + FILE* run_no_file=fopen(last_run_file.c_str(),"r"); + if (run_no_file) { + fscanf(run_no_file,"%d",&run); + fclose(run_no_file); + run=run+1; + } + + time_t t = time(NULL); + struct tm *tm = localtime(&t); + struct tm *gmtm = gmtime(&t); + + run=BaseMenu::readline_int("Run number? ",run); + + char fname_def_format[1024]; + sprintf(fname_def_format,"run%06d_%%Y%%m%%d_%%H%%M%%S.raw",run); + char fname_def[1024]; + strftime(fname_def, sizeof(fname_def), fname_def_format, tm); + + std::string fname=BaseMenu::readline("Filename : ", fname_def); + FILE* f=fopen(fname.c_str(),"w"); + + int event_target=BaseMenu::readline_int("Target events? ",1000); + pft->backend->daq_setup_event_tag(run,gmtm->tm_mday,gmtm->tm_mon+1,gmtm->tm_hour,gmtm->tm_min); + + // reset various counters + pft->prepareNewRun(); + + // enable external triggers + pft->backend->fc_enables(true,true,false); + + int ievent=0; + while (ieventbackend->daq_status(full, empty, samples, esize); + } while (empty); + printf("%d: %d samples waiting for readout...\n",ievent,samples); + + if (f) { + std::vector event = pft->daqReadEvent(); + fwrite(&(event[0]),sizeof(uint32_t),event.size(),f); + } + + ievent++; + } + + // disable external triggers + pft->backend->fc_enables(false,true,false); + + fclose(f); + + run_no_file=fopen(last_run_file.c_str(),"w"); + if (run_no_file) { + fprintf(run_no_file,"%d\n",run); + fclose(run_no_file); + } + } if (cmd=="PEDESTAL" || cmd=="CHARGE") { std::string fname_def_format = "pedestal_%Y%m%d_%H%M%S.raw"; if (cmd=="CHARGE") fname_def_format = "charge_%Y%m%d_%H%M%S.raw"; @@ -1168,6 +1233,8 @@ void prepareOpts(Rcfile& rcfile) { "Full path to directory containgin IP-bus mapping. Only required for uHal comm."); rcfile.declareString("default_hostname", "Hostname of polarfire to connect to if none are given on the command line"); + rcfile.declareString("runnumber_file", + "Full path to a file which contains the last run number"); } /** @@ -1239,6 +1306,7 @@ int main(int argc, char* argv[]) { options.load("pftoolrc"); if (file_exists(home+"/.pftoolrc")) options.load(home+"/.pftoolrc"); + /***************************************************************************** * Parse Command Line Parameters @@ -1353,6 +1421,9 @@ int main(int argc, char* argv[]) { return 3; } + if (options.contents().has_key("runnumber_file")) + last_run_file=options.contents().getString("runnumber_file"); + if (p_pft) { // prepare the links if (options.contents().is_vector("roclinks")) { From 1d76bed355fa63ece419950a307b291c51dcf20a Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Tue, 29 Mar 2022 05:16:45 -0500 Subject: [PATCH 02/37] Missing text --- tool/pftool.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tool/pftool.cc b/tool/pftool.cc index 19ca5ff4..dc62ec87 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -1184,6 +1184,7 @@ static void RunMenu( PolarfireTarget* pft_ ) { pfMenu::Line("HARD_RESET", "Reset the DAQ, including all parameters", &daq), pfMenu::Line("PEDESTAL","Take a simple random pedestal run", &daq), pfMenu::Line("CHARGE","Take a charge-injection run", &daq), + pfMenu::Line("EXTERNAL","Take an externally-triggered run", &daq), pfMenu::Line("SCAN","Take many charge or pedestal runs while changing a single parameter", &daq), pfMenu::Line("QUIT","Back to top menu") }); From 3c8aadf8fe6cd17d6a1da3ac208e462ad2438ea0 Mon Sep 17 00:00:00 2001 From: pbutti Date: Wed, 30 Mar 2022 12:07:45 +0200 Subject: [PATCH 03/37] Add a hacky way to launch/stop DMA --- tool/pftool.cc | 64 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index dc62ec87..12711ee4 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -515,7 +515,7 @@ static void fc( const std::string& cmd, PolarfireTarget* pft ) { printf(" Single bit errors: %d Double bit errors: %d\n",sbe,dbe); std::vector cnt=pft->hcal.fc().getCmdCounters(); for (int i=0; i<8; i++) - printf(" Bit %d count: %20u (%s)\n",i,cnt[i],bit_comments.at(i)); + printf(" Bit %d count: %20u (%s)\n",i,cnt[i],bit_comments.at(i).c_str()); int spill_count, header_occ, event_count,vetoed_counter; pft->backend->fc_read_counters(spill_count, header_occ, event_count, vetoed_counter); printf(" Spills: %d Events: %d Header occupancy: %d Vetoed L1A: %d\n",spill_count,event_count,header_occ,vetoed_counter); @@ -624,6 +624,9 @@ static void daq_setup( const std::string& cmd, PolarfireTarget* pft ) { static std::string last_run_file=".last_run_file"; +static std::string start_dma_cmd=""; +static std::string stop_dma_cmd=""; + /** * DAQ menu commands, DOES NOT include sub-menu commands @@ -710,7 +713,8 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { strftime(fname_def, sizeof(fname_def), fname_def_format, tm); std::string fname=BaseMenu::readline("Filename : ", fname_def); - FILE* f=fopen(fname.c_str(),"w"); + FILE* f=0; + if (!dma_enabled) f=fopen(fname.c_str(),"w"); int event_target=BaseMenu::readline_int("Target events? ",1000); pft->backend->daq_setup_event_tag(run,gmtm->tm_mday,gmtm->tm_mon+1,gmtm->tm_hour,gmtm->tm_min); @@ -718,31 +722,55 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { // reset various counters pft->prepareNewRun(); + // start DMA, if that's what we're doing... + if (dma_enabled && !start_dma_cmd.empty()) { + printf("Launching DMA...\n"); + std::string cmd=start_dma_cmd+" "+fname; + system(cmd.c_str()); + } + // enable external triggers pft->backend->fc_enables(true,true,false); - int ievent=0; + int ievent=0, wasievent=0; while (ieventbackend->daq_status(full, empty, samples, esize); - } while (empty); - printf("%d: %d samples waiting for readout...\n",ievent,samples); - - if (f) { - std::vector event = pft->daqReadEvent(); - fwrite(&(event[0]),sizeof(uint32_t),event.size(),f); + if (dma_enabled) { + int spill,occ,vetoed; + pft->backend->fc_read_counters(spill,occ,ievent,vetoed); + if (ievent>wasievent) { + printf("...Now read %d events\n",ievent); + wasievent=ievent; + } else { + sleep(1); + } + } else { + bool full, empty; + int samples, esize; + do { + pft->backend->daq_status(full, empty, samples, esize); + } while (empty); + printf("%d: %d samples waiting for readout...\n",ievent,samples); + + if (f) { + std::vector event = pft->daqReadEvent(); + fwrite(&(event[0]),sizeof(uint32_t),event.size(),f); + } + + ievent++; } - - ievent++; } // disable external triggers pft->backend->fc_enables(false,true,false); - fclose(f); + if (f) fclose(f); + + if (dma_enabled && !stop_dma_cmd.empty()) { + printf("Stopping DMA...\n"); + std::string cmd=stop_dma_cmd; + system(cmd.c_str()); + } run_no_file=fopen(last_run_file.c_str(),"w"); if (run_no_file) { @@ -1424,6 +1452,10 @@ int main(int argc, char* argv[]) { if (options.contents().has_key("runnumber_file")) last_run_file=options.contents().getString("runnumber_file"); + if (options.contents().has_key("start_dma_command")) + start_dma_cmd=options.contents().getString("start_dma_command"); + if (options.contents().has_key("stop_dma_command")) + stop_dma_cmd=options.contents().getString("stop_dma_command"); if (p_pft) { // prepare the links From 7f3fab85c0793f967f9ac39b9b02fcda95f6bfc1 Mon Sep 17 00:00:00 2001 From: pbutti Date: Wed, 30 Mar 2022 18:06:09 +0200 Subject: [PATCH 04/37] Allow for defaults when entering nothing --- tool/Menu.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tool/Menu.cc b/tool/Menu.cc index e7757868..4ee46a81 100644 --- a/tool/Menu.cc +++ b/tool/Menu.cc @@ -31,7 +31,8 @@ std::string BaseMenu::readline(const std::string& prompt, if (!cmdTextQueue_.empty()) { retval = cmdTextQueue_.front(); - printf("%s %s\n", trueprompt.c_str(), retval.c_str()); + if (retval.empty()) retval=defval; + printf("%s %s\n", trueprompt.c_str(), retval.c_str()); if (!retval.empty() && retval[0] == '~') { retval.erase(0, 1); From 205d796bf1ec7432f4ac74d12da9468d460ad33d Mon Sep 17 00:00:00 2001 From: pbutti Date: Wed, 30 Mar 2022 20:49:47 +0200 Subject: [PATCH 05/37] Move when the run number is written down --- tool/pftool.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 12711ee4..0437e9ef 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -713,6 +713,13 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { strftime(fname_def, sizeof(fname_def), fname_def_format, tm); std::string fname=BaseMenu::readline("Filename : ", fname_def); + + run_no_file=fopen(last_run_file.c_str(),"w"); + if (run_no_file) { + fprintf(run_no_file,"%d\n",run); + fclose(run_no_file); + } + FILE* f=0; if (!dma_enabled) f=fopen(fname.c_str(),"w"); @@ -772,11 +779,6 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { system(cmd.c_str()); } - run_no_file=fopen(last_run_file.c_str(),"w"); - if (run_no_file) { - fprintf(run_no_file,"%d\n",run); - fclose(run_no_file); - } } if (cmd=="PEDESTAL" || cmd=="CHARGE") { std::string fname_def_format = "pedestal_%Y%m%d_%H%M%S.raw"; From 999239644e6e4b3813766a5e9f65dd866831784a Mon Sep 17 00:00:00 2001 From: pbutti Date: Thu, 31 Mar 2022 17:42:49 +0200 Subject: [PATCH 06/37] Fix bug with ZS particularly for link 0 --- src/pflib/PolarfireTarget.cxx | 6 +++++- tool/pftool.cc | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index fcd0608d..1487422a 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -299,7 +299,7 @@ void PolarfireTarget::daqStatus(std::ostream& os) { void PolarfireTarget::enableZeroSuppression(int link, bool full_suppress) { for (int i{0}; i < NLINKS; i++) { - if (i != link and link > 0) continue; + if (i != link and link >= 0) continue; uint32_t reg = wb->wb_read(tgt_DAQ_LinkFmt,(i<<7)|1); bool wasZS = (reg & 0x2)!=0; if (link >= 0 and not wasZS) { @@ -411,13 +411,17 @@ bool PolarfireTarget::loadBiasSettings(const std::string& file_name) { std::cout << "WARNING: Ignoring Bias CSV settings line" "without exactly four columns." + << std::endl; } }); + return true; } else if (endsWith(file_name, ".yaml") or endsWith(file_name, ".yml")) { std::cerr << "Loading settings from YAML not implemented here yet." << std::endl; + return false; } else { std::cerr << file_name << " has no recognized extension (.csv, .yaml, .yml)" << std::endl; + return false; } } diff --git a/tool/pftool.cc b/tool/pftool.cc index bd04c168..6d355d62 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -571,7 +571,7 @@ static void daq_setup( const std::string& cmd, PolarfireTarget* pft ) { } if (cmd=="ZS") { int jlink=BaseMenu::readline_int("Which link (-1 for all)? ",-1); - bool fullSuppress=BaseMenu::readline_bool("Suppress all channels? ",false); + bool fullSuppress=BaseMenu::readline_bool("Suppress all channels? ",false); pft->enableZeroSuppression(jlink,fullSuppress); } if (cmd=="L1APARAMS") { From a7b759325bab4a313450763d6eea8c1705553fa5 Mon Sep 17 00:00:00 2001 From: pbutti Date: Thu, 31 Mar 2022 17:48:13 +0200 Subject: [PATCH 07/37] Add disable/enable in the ZS call --- src/pflib/PolarfireTarget.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index 1487422a..f49d8f15 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -298,6 +298,10 @@ void PolarfireTarget::daqStatus(std::ostream& os) { } void PolarfireTarget::enableZeroSuppression(int link, bool full_suppress) { + auto& daq = hcal.daq(); + bool enabled=daq.enabled(); + + if (enabled) daq.enable(false); for (int i{0}; i < NLINKS; i++) { if (i != link and link >= 0) continue; uint32_t reg = wb->wb_read(tgt_DAQ_LinkFmt,(i<<7)|1); @@ -306,8 +310,10 @@ void PolarfireTarget::enableZeroSuppression(int link, bool full_suppress) { reg |= 0x4; if (not full_suppress) reg ^= 0x4; } + wb->wb_write(tgt_DAQ_LinkFmt,(i<<7)|1,reg^0x2); } + if (enabled) daq.enable(true); } void PolarfireTarget::daqSoftReset() { From 3c9c349475012bd259df14d48efd412cca118465 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Sat, 2 Apr 2022 14:55:34 +0200 Subject: [PATCH 08/37] Initial add of task menu --- CMakeLists.txt | 2 +- tool/pftool.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 645350d1..aaae423a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,7 @@ else() endif() if (NOT Rogue_FOUND AND NOT Uhal_FOUND) - message(FATAL_ERROR "Neither Rogue or Uhal were found. At least one is necessary for polarfire interaction library.") + message(WARNING "Neither Rogue or Uhal were found. At least one is necessary for a functional polarfire interaction library.") endif() set_target_properties(pflib ${comm_libs} PROPERTIES PREFIX "libpflib_") diff --git a/tool/pftool.cc b/tool/pftool.cc index c2c78ef6..2f051a6b 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -875,6 +875,56 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { } } +/** + * TASK menu commands + * + * ## Commands + * - SCANCHARGE : loop over channels and scan a range of a CALIBDAC values, recording only relevant channel points in CSV file + * + * @param[in] cmd command selected from menu + * @param[in] pft active target + */ +static void tasks( const std::string& cmd, PolarfireTarget* pft ) { + pflib::DAQ& daq=pft->hcal.daq(); + + int low_value=0; + int high_value=0; + int steps=-1; + + if (cmd=="SCANCHARGE") { + + } + if (cmd=="SCANCHARGE") { + static const int MAX_ELINK_CHAN=35; + + for (int step=0; stephcal.elinks().nlinks()/2; iroc++) { + if (!pft->hcal.elinks().isActive(iroc*2)) continue; + + // set the value + } + //////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////// + /// Enable charge injection channel by channel -- per elink + for (int ichan=0; ichan<=MAX_ELINK_CHAN; ichan++) { + + ////////////////////////////////////////////////////////// + /// Take the expected number of events and save the events + + ////////////////////////////////////////////////////////// + + } + //////////////////////////////////////////////////////////// + } + } +} + /** * Print data words from raw binary file and return them * @return vector of 32-bit data words in file @@ -1227,7 +1277,7 @@ static void RunMenu( PolarfireTarget* pft_ ) { pfMenu::Line("PEDESTAL","Take a simple random pedestal run", &daq), pfMenu::Line("CHARGE","Take a charge-injection run", &daq), pfMenu::Line("EXTERNAL","Take an externally-triggered run", &daq), - pfMenu::Line("SCAN","Take many charge or pedestal runs while changing a single parameter", &daq), + // pfMenu::Line("SCAN","Take many charge or pedestal runs while changing a single parameter", &daq), pfMenu::Line("QUIT","Back to top menu") }); @@ -1237,9 +1287,18 @@ static void RunMenu( PolarfireTarget* pft_ ) { pfMenu::Line("I2C","Access the I2C Core", &menu_i2c ), pfMenu::Line("QUIT","Back to top menu") }); + + pfMenu menu_tasks({ + pfMenu::Line("SCANCHARGE","Charge scan over all active channels", &tasks), + pfMenu::Line("DELAYSCAN","Charge injection delay scan", &tasks ), + pfMenu::Line("QUIT","Back to top menu") + }); + + pfMenu menu_utop({ pfMenu::Line("STATUS","Status summary", &status), + pfMenu::Line("TASKS","Various high-level tasks like scans", &menu_tasks ), pfMenu::Line("FAST_CONTROL","Fast Control", &menu_fc ), pfMenu::Line("ROC","ROC Configuration", &menu_roc ), pfMenu::Line("BIAS","BIAS voltage setting", &menu_bias ), From 1c648fffc65b71e547036d6a268e17d2f6e2edb1 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Sat, 2 Apr 2022 15:06:25 +0200 Subject: [PATCH 09/37] Main loop coded --- tool/pftool.cc | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 2f051a6b..d8384bd9 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -887,35 +887,57 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { static void tasks( const std::string& cmd, PolarfireTarget* pft ) { pflib::DAQ& daq=pft->hcal.daq(); - int low_value=0; - int high_value=0; - int steps=-1; + static int low_value=10; + static int high_value=500; + static int steps=10; + static int events_per_step=100; + std::string pagetemplate; + std::string valuename; if (cmd=="SCANCHARGE") { - + valuename="CALIB_DAC"; + pagetemplate="REFERENCE_VOLTAGE_%d"; + low_value=BaseMenu::readline_int("Smallest value of CALIB_DAC?",low_value); + high_value=BaseMenu::readline_int("Largest value of CALIB_DAC?",high_value); + steps=BaseMenu::readline_int("Number of steps?",steps); + events_per_step=BaseMenu::readline_int("Events per step?",events_per_step); } if (cmd=="SCANCHARGE") { static const int MAX_ELINK_CHAN=35; for (int step=0; stephcal.elinks().nlinks()/2; iroc++) { - if (!pft->hcal.elinks().isActive(iroc*2)) continue; + for (int ilink=0; irochcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + int iroc=ilink/2; + char pagename[32]; + snprintf(pagename,32,pagetemplate.c_str(),ilink%2); // set the value + pft->hcal.roc(iroc).applyParameter(pagename, valuename, value); } //////////////////////////////////////////////////////////// + pft->prepareNewRun(); + //////////////////////////////////////////////////////////// /// Enable charge injection channel by channel -- per elink for (int ichan=0; ichan<=MAX_ELINK_CHAN; ichan++) { ////////////////////////////////////////////////////////// /// Take the expected number of events and save the events + for (int ievt=0; ievtbackend->fc_sendL1A(); + std::vector event = pft->daqReadEvent(); + + // here we decode the event and store the relevant information only... + + } ////////////////////////////////////////////////////////// From b0da4ee625bb9e29e0109db1e713e577f11fbbd2 Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Sat, 2 Apr 2022 15:20:18 +0200 Subject: [PATCH 10/37] Add output except for decoding --- tool/pftool.cc | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index d8384bd9..bbf1bfb1 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -401,8 +401,8 @@ static void roc( const std::string& cmd, PolarfireTarget* pft ) { if (cmd=="DUMP") { std::string fname_def_format = "hgcroc_"+std::to_string(iroc)+"_settings_%Y%m%d_%H%M%S.yaml"; - time_t t = time(NULL); - struct tm *tm = localtime(&t); + time_t t = time(NULL) +; struct tm *tm = localtime(&t); char fname_def[64]; strftime(fname_def, sizeof(fname_def), fname_def_format.c_str(), tm); @@ -893,16 +893,42 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { static int events_per_step=100; std::string pagetemplate; std::string valuename; + + int nsamples=1; + { + bool multi; + int nextra; + pft->hcal.fc().getMultisampleSetup(multi,nextra); + if (multi) nsamples=nextra+1; + } if (cmd=="SCANCHARGE") { valuename="CALIB_DAC"; pagetemplate="REFERENCE_VOLTAGE_%d"; low_value=BaseMenu::readline_int("Smallest value of CALIB_DAC?",low_value); - high_value=BaseMenu::readline_int("Largest value of CALIB_DAC?",high_value); - steps=BaseMenu::readline_int("Number of steps?",steps); - events_per_step=BaseMenu::readline_int("Events per step?",events_per_step); + high_value=BaseMenu::readline_int("Largest value of CALIB_DAC?",high_value); } + /// common stuff for all scans if (cmd=="SCANCHARGE") { + + steps=BaseMenu::readline_int("Number of steps?",steps); + events_per_step=BaseMenu::readline_int("Events per step?",events_per_step); + + time_t t=time(NULL); + struct tm *tm = localtime(&t); + char fname_def_format[1024]; + sprintf(fname_def_format,"scan_%s_%%Y%%m%%d_%%H%%M%%S.raw",valuename.c_str()); + char fname_def[1024]; + strftime(fname_def, sizeof(fname_def), fname_def_format, tm); + + std::string fname=BaseMenu::readline("Filename : ", fname_def); + std::ofstream csv_out=std::ofstream(fname); + + // csv header + csv_out < event = pft->daqReadEvent(); // here we decode the event and store the relevant information only... - + + for (int ilink=0; irochcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + csv_out << value << ',' << ilink << ',' << ichan << ',' << ievt; + for (int i=0; i Date: Sat, 2 Apr 2022 15:21:51 +0200 Subject: [PATCH 11/37] add power up functionality --- tool/pftool.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index d8384bd9..219f5546 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -879,6 +879,7 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { * TASK menu commands * * ## Commands + * - RESET_POWERUP: execute a series of commands after chip has been power cycled or firmware re-loaded * - SCANCHARGE : loop over channels and scan a range of a CALIBDAC values, recording only relevant channel points in CSV file * * @param[in] cmd command selected from menu @@ -893,6 +894,14 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { static int events_per_step=100; std::string pagetemplate; std::string valuename; + + if (cmd=="RESET_POWERUP") { + pft->hcal.fc().resetTransmitter(); + pft->hcal.resyncLoadROC(); + pft->daqHardReset(); + pflib::Elinks& elinks=pft->hcal.elinks(); + elinks.resetHard(); + } if (cmd=="SCANCHARGE") { valuename="CALIB_DAC"; @@ -1310,7 +1319,8 @@ static void RunMenu( PolarfireTarget* pft_ ) { pfMenu::Line("QUIT","Back to top menu") }); - pfMenu menu_tasks({ + pfMenu menu_tasks({ + pfMenu::Line("RESET_POWERUP", "Execute FC,ELINKS,DAQ reset after power up", &tasks), pfMenu::Line("SCANCHARGE","Charge scan over all active channels", &tasks), pfMenu::Line("DELAYSCAN","Charge injection delay scan", &tasks ), pfMenu::Line("QUIT","Back to top menu") From 9ad2d9940f71fbe6d4eb8bc822388a1ec376856e Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Sat, 2 Apr 2022 15:34:03 +0200 Subject: [PATCH 12/37] Turn on/off charge injection by channel --- tool/pftool.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index bbf1bfb1..81b7726a 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -910,6 +910,7 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { } /// common stuff for all scans if (cmd=="SCANCHARGE") { + static const int NUM_ELINK_CHAN=36; steps=BaseMenu::readline_int("Number of steps?",steps); events_per_step=BaseMenu::readline_int("Events per step?",events_per_step); @@ -929,7 +930,21 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { for (int i=0; ihcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + int iroc=ilink/2; + for (int ichan=0; ichanhcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 0); + pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); + } + } + //////////////////////////////////////////////////////////// for (int step=0; stephcal.elinks().nlinks(); ilink++) { + for (int ilink=0; ilinkhcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; int iroc=ilink/2; @@ -948,12 +963,25 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { } //////////////////////////////////////////////////////////// + printf(" Scan %s=%d...\n",valuename.c_str(),value); + pft->prepareNewRun(); - //////////////////////////////////////////////////////////// - /// Enable charge injection channel by channel -- per elink - for (int ichan=0; ichan<=MAX_ELINK_CHAN; ichan++) { + for (int ichan=0; ichanhcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + int iroc=ilink/2; + char pagename[32]; + snprintf(pagename,32,"CHANNEL_%d",(ilink%2)*(NUM_ELINK_CHAN)+ichan); + // set the value + pft->hcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 1); + // pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); + } + ////////////////////////////////////////////////////////// /// Take the expected number of events and save the events for (int ievt=0; ievthcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + int iroc=ilink/2; + char pagename[32]; + snprintf(pagename,32,"CHANNEL_%d",(ilink%2)*(NUM_ELINK_CHAN)+ichan); + // set the value + pft->hcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 0); + // pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); + } + ////////////////////////////////////////////////////////// } From b9c6eb63bd469b7f5e464245b41e9f6d2a74721b Mon Sep 17 00:00:00 2001 From: Jeremiah Mans Date: Sat, 2 Apr 2022 15:38:39 +0200 Subject: [PATCH 13/37] More iroc bugs --- tool/pftool.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 81b7726a..41cb2a0d 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -918,7 +918,7 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { time_t t=time(NULL); struct tm *tm = localtime(&t); char fname_def_format[1024]; - sprintf(fname_def_format,"scan_%s_%%Y%%m%%d_%%H%%M%%S.raw",valuename.c_str()); + sprintf(fname_def_format,"scan_%s_%%Y%%m%%d_%%H%%M%%S.csv",valuename.c_str()); char fname_def[1024]; strftime(fname_def, sizeof(fname_def), fname_def_format, tm); @@ -926,11 +926,13 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { std::ofstream csv_out=std::ofstream(fname); // csv header - csv_out <hcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; @@ -947,7 +949,9 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { //////////////////////////////////////////////////////////// for (int step=0; stepprepareNewRun(); for (int ichan=0; ichanhcal.elinks().nlinks(); ilink++) { + for (int ilink=0; ilinkhcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; csv_out << value << ',' << ilink << ',' << ichan << ',' << ievt; From ef3ac44f5ae77561a9ffded5b75b09c1e44a7d27 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 15:42:14 +0200 Subject: [PATCH 14/37] Fix ordering, ready for decoding --- tool/pftool.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 41cb2a0d..38e5d714 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -950,12 +950,12 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { for (int step=0; stephcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; From 288fb4e51b8554c2cec007b47d1aad9199fb6c63 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:03:01 +0200 Subject: [PATCH 15/37] Initial header for RocPacket --- include/pflib/decoding/RocPacket.h | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 include/pflib/decoding/RocPacket.h diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h new file mode 100644 index 00000000..eaa5e1d7 --- /dev/null +++ b/include/pflib/decoding/RocPacket.h @@ -0,0 +1,33 @@ +#ifndef pflib_decoding_RocPacket_h +#define pflib_decoding_RocPacket_h 1 + +#include + +namespace pflib { +namespace decoding { + +/** \class This class decodes the innermost part of an HGCROC packet given + a pointer to a series of unsigned 32-bit integers and a length. +*/ +class RocPacket { + public: + RocPacket(const uint32_t* header_ptr, int len); + + int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} + + bool has_chan(int ichan) const; + + private: + int offset_to_chan(int ichan) const; + + + const uint32_t* data_; + int length_; + +}; + +} +} + +#endif// pflib_decoding_RocPacket_h + From c0207d3f2b2b3de895ac53b7e12a2c48915df5c1 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:20:58 +0200 Subject: [PATCH 16/37] Read subpacket header --- include/pflib/decoding/RocPacket.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index eaa5e1d7..06a1f05a 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -15,11 +15,16 @@ class RocPacket { int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} - bool has_chan(int ichan) const; + int crc() const {if (length_==0) return -1; return (data_[0]>>15)&0x1}; + + int bxid() const { if (length_<3) return -1; return (data_[2]>>11)&0x7FF;} + + int wadd() const { if (length_<3) return -1; return (data_[2]>>3(&0xFF)}; + + bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1}; private: int offset_to_chan(int ichan) const; - const uint32_t* data_; int length_; From 35b6610c814cb4b4b49c3a184b054a85f8172a7f Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:21:57 +0200 Subject: [PATCH 17/37] Adding RocPacket to Make --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaae423a..538509cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,9 @@ add_library(pflib SHARED src/pflib/ROC.cxx src/pflib/WishboneTarget.cxx src/pflib/Compile.cxx - src/pflib/PolarfireTarget.cxx) + src/pflib/PolarfireTarget.cxx + src/pflib/decoding/RocPacket.cxx +) target_include_directories(pflib PUBLIC "$" "$") From 4ce08b242e20685895339fe5366867546198dcfd Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:24:20 +0200 Subject: [PATCH 18/37] Added CXX --- src/pflib/decoding/RocPacket.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/pflib/decoding/RocPacket.cxx diff --git a/src/pflib/decoding/RocPacket.cxx b/src/pflib/decoding/RocPacket.cxx new file mode 100644 index 00000000..3a2aa779 --- /dev/null +++ b/src/pflib/decoding/RocPacket.cxx @@ -0,0 +1,25 @@ +#include "pflib/decoding/RocPacket.h" + +namespace pflib { +namespace decoding { + +int RocPacket::offset_to_chan(int ichan) const { + if (length_<2 || ichan<0 || ichan>=36) return -1; + int offset=0; + + uint64_t readout_map=(uint64_t(data_[0])<<32)|data_[1]; + + int inominal=ichan+1; // first word in ROC V2 is header + if (ichan>=18) inominal+=2; // common mode and calib in the middle + + for (int i=0; i>1; + } + if (readout_map&0x1) return offset+2; // +2 for the two Polarfire header words + else return -1; + +} + +} +} From 1f72e513c30a0d4d64c380f38a6ed935734954cd Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:25:42 +0200 Subject: [PATCH 19/37] Fixed syntax errors in subpacket header --- include/pflib/decoding/RocPacket.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index 06a1f05a..281cfa2d 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -15,13 +15,13 @@ class RocPacket { int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} - int crc() const {if (length_==0) return -1; return (data_[0]>>15)&0x1}; + int crc() const {if (length_==0) return -1; return (data_[0]>>15)&0x1;} int bxid() const { if (length_<3) return -1; return (data_[2]>>11)&0x7FF;} - int wadd() const { if (length_<3) return -1; return (data_[2]>>3(&0xFF)}; + int wadd() const { if (length_<3) return -1; return (data_[2]>>3)&0xFF;} - bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1}; + bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1;} private: int offset_to_chan(int ichan) const; From ae2e2d5278adbb94a2fcfaf3bab72f1831f2a902 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:32:48 +0200 Subject: [PATCH 20/37] Read TOA, TOT and ADC from subpacket --- include/pflib/decoding/RocPacket.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index 281cfa2d..410fdfbf 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -22,7 +22,13 @@ class RocPacket { int wadd() const { if (length_<3) return -1; return (data_[2]>>3)&0xFF;} bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1;} - + + int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>34)&0x1FFFF;} + + int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>17)&0x1FFFF;} + + int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x1FFFF;} + private: int offset_to_chan(int ichan) const; From d950a6dd6711b428a9b40c00421f747e4592f392 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:34:43 +0200 Subject: [PATCH 21/37] Added next level up --- CMakeLists.txt | 1 + include/pflib/decoding/PolarfirePacket.h | 33 ++++++++++++++++++++++++ include/pflib/decoding/RocPacket.h | 2 +- src/pflib/decoding/PolarfirePacket.cxx | 7 +++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 include/pflib/decoding/PolarfirePacket.h create mode 100644 src/pflib/decoding/PolarfirePacket.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 538509cd..818dc294 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ add_library(pflib SHARED src/pflib/Compile.cxx src/pflib/PolarfireTarget.cxx src/pflib/decoding/RocPacket.cxx + src/pflib/decoding/PolarfirePacket.cxx ) target_include_directories(pflib PUBLIC "$" diff --git a/include/pflib/decoding/PolarfirePacket.h b/include/pflib/decoding/PolarfirePacket.h new file mode 100644 index 00000000..319b023a --- /dev/null +++ b/include/pflib/decoding/PolarfirePacket.h @@ -0,0 +1,33 @@ +#ifndef pflib_decoding_PolarfirePacket_h +#define pflib_decoding_PolarfirePacket_h 1 + +#include "pflib/decoding/RocPacket.h" + +namespace pflib { +namespace decoding { + + /** \class This class decodes the innermost part of an HGCROC packet given + a pointer to a series of unsigned 32-bit integers and a length. +*/ +class PolarfirePacket { + public: + PolarfirePacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { } + + int length() const { if (length_<1) return -1; return data_[0]&0xFFF; } + int nlinks() const { if (length_<1) return -1; return (data_[0]>>14)&0x3F; } + int fpgaid() const { if (length_<1) return -1; return (data_[0]>>20)&0xFF; } + int formatversion() const { if (length_<1) return -1; return (data_[0]>>28)&0xF; } + + RocPacket roc(int iroc) const; +private: + int offset_to_roc(int iroc) const; + + const uint32_t* data_; + int length_; +}; + +} +} + +#endif// pflib_decoding_PolarfirePacket_h + diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index 410fdfbf..e2ffbc13 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -11,7 +11,7 @@ namespace decoding { */ class RocPacket { public: - RocPacket(const uint32_t* header_ptr, int len); + RocPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { } int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} diff --git a/src/pflib/decoding/PolarfirePacket.cxx b/src/pflib/decoding/PolarfirePacket.cxx new file mode 100644 index 00000000..c648940c --- /dev/null +++ b/src/pflib/decoding/PolarfirePacket.cxx @@ -0,0 +1,7 @@ +#include "pflib/decoding/PolarfirePacket.h" + +namespace pflib { +namespace decoding { + +} +} From cc3156c002a2db09d8d2335037afc417cafaf296 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:40:58 +0200 Subject: [PATCH 22/37] Working on the packet header --- include/pflib/decoding/PolarfirePacket.h | 4 +++- src/pflib/decoding/PolarfirePacket.cxx | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/pflib/decoding/PolarfirePacket.h b/include/pflib/decoding/PolarfirePacket.h index 319b023a..9c9219c0 100644 --- a/include/pflib/decoding/PolarfirePacket.h +++ b/include/pflib/decoding/PolarfirePacket.h @@ -18,9 +18,11 @@ class PolarfirePacket { int fpgaid() const { if (length_<1) return -1; return (data_[0]>>20)&0xFF; } int formatversion() const { if (length_<1) return -1; return (data_[0]>>28)&0xF; } + int length_for_elink(int ilink) const { if (ilink>=nlinks) return 0; return (data_[2+(ilink/4)]>>(8*(ilink%4)))&0x3F; } + RocPacket roc(int iroc) const; private: - int offset_to_roc(int iroc) const; + int offset_to_elink(int iroc) const; const uint32_t* data_; int length_; diff --git a/src/pflib/decoding/PolarfirePacket.cxx b/src/pflib/decoding/PolarfirePacket.cxx index c648940c..2df2a26e 100644 --- a/src/pflib/decoding/PolarfirePacket.cxx +++ b/src/pflib/decoding/PolarfirePacket.cxx @@ -3,5 +3,19 @@ namespace pflib { namespace decoding { +RocPacket PolarfirePacket::roc(int ilink) const { + int offset=offset_to_elink(ilink); + if (offset<0) return RocPacket(0,0); + else return RocPacket(data_+offset,length_for_elink(ilink)); +} + +int PolarfirePacket::offset_to_elink(int ilink) const { + if (ilink<0 || ilink>=nlinks()) return -1; + offset=2+((nlinks()+3)/4); // header words + for (int i=0; i Date: Sat, 2 Apr 2022 16:42:46 +0200 Subject: [PATCH 23/37] Seems ready --- include/pflib/decoding/PolarfirePacket.h | 2 +- src/pflib/decoding/PolarfirePacket.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pflib/decoding/PolarfirePacket.h b/include/pflib/decoding/PolarfirePacket.h index 9c9219c0..464e51b5 100644 --- a/include/pflib/decoding/PolarfirePacket.h +++ b/include/pflib/decoding/PolarfirePacket.h @@ -18,7 +18,7 @@ class PolarfirePacket { int fpgaid() const { if (length_<1) return -1; return (data_[0]>>20)&0xFF; } int formatversion() const { if (length_<1) return -1; return (data_[0]>>28)&0xF; } - int length_for_elink(int ilink) const { if (ilink>=nlinks) return 0; return (data_[2+(ilink/4)]>>(8*(ilink%4)))&0x3F; } + int length_for_elink(int ilink) const { if (ilink>=nlinks()) return 0; return (data_[2+(ilink/4)]>>(8*(ilink%4)))&0x3F; } RocPacket roc(int iroc) const; private: diff --git a/src/pflib/decoding/PolarfirePacket.cxx b/src/pflib/decoding/PolarfirePacket.cxx index 2df2a26e..4848318b 100644 --- a/src/pflib/decoding/PolarfirePacket.cxx +++ b/src/pflib/decoding/PolarfirePacket.cxx @@ -11,7 +11,7 @@ RocPacket PolarfirePacket::roc(int ilink) const { int PolarfirePacket::offset_to_elink(int ilink) const { if (ilink<0 || ilink>=nlinks()) return -1; - offset=2+((nlinks()+3)/4); // header words + int offset=2+((nlinks()+3)/4); // header words for (int i=0; i Date: Sat, 2 Apr 2022 16:45:26 +0200 Subject: [PATCH 24/37] Corrected reading of rocpacket header --- include/pflib/decoding/RocPacket.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index e2ffbc13..461134ed 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -23,11 +23,11 @@ class RocPacket { bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1;} - int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>34)&0x1FFFF;} + int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>20)&0x2FF;} - int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>17)&0x1FFFF;} + int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>10)&0x2FF;} - int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x1FFFF;} + int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x2FF;} private: int offset_to_chan(int ichan) const; From 9272229c0273d3726e4d85e6d5ab7b8e7433192f Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:45:52 +0200 Subject: [PATCH 25/37] Read polarfire packet header --- include/pflib/decoding/PolarfirePacket.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/pflib/decoding/PolarfirePacket.h b/include/pflib/decoding/PolarfirePacket.h index 464e51b5..d5c0725c 100644 --- a/include/pflib/decoding/PolarfirePacket.h +++ b/include/pflib/decoding/PolarfirePacket.h @@ -20,6 +20,18 @@ class PolarfirePacket { int length_for_elink(int ilink) const { if (ilink>=nlinks()) return 0; return (data_[2+(ilink/4)]>>(8*(ilink%4)))&0x3F; } + int bxid() const { if (length_<2) return -1; return (data_[1]>>20)&0xFFF;} + + int rreq() const { if (length_<2) return -1; return (data_[1]>>10)&0x3FF;} + + int orbit() const { if (length_<2) return -1; return data_[1]&0x3FF;} + + int linklen(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8))&0x3F;} + + int linkcrc(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8+6))&0x1;} + + int linkrid(int link) const { if (length_<3) return -1; return (data_[2]>>(link*8+7))&0x1;} + RocPacket roc(int iroc) const; private: int offset_to_elink(int iroc) const; From 20ec9861bb4e334f46344760c9d5ea030cc866dc Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:50:09 +0200 Subject: [PATCH 26/37] SuperPacket shows up --- CMakeLists.txt | 1 + include/pflib/decoding/SuperPacket.h | 33 ++++++++++++++++++++++++++++ src/pflib/decoding/SuperPacket.cxx | 18 +++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 include/pflib/decoding/SuperPacket.h create mode 100644 src/pflib/decoding/SuperPacket.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 818dc294..b0f08032 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ add_library(pflib SHARED src/pflib/PolarfireTarget.cxx src/pflib/decoding/RocPacket.cxx src/pflib/decoding/PolarfirePacket.cxx + src/pflib/decoding/SuperPacket.cxx ) target_include_directories(pflib PUBLIC "$" diff --git a/include/pflib/decoding/SuperPacket.h b/include/pflib/decoding/SuperPacket.h new file mode 100644 index 00000000..d81d766f --- /dev/null +++ b/include/pflib/decoding/SuperPacket.h @@ -0,0 +1,33 @@ +#ifndef pflib_decoding_SuperPacket_h +#define pflib_decoding_SuperPacket_h 1 + +#include "pflib/decoding/PolarfirePacket.h" + +namespace pflib { +namespace decoding { + + /** \class This class decodes the outer level of a multisample packet + */ +class SuperPacket { + public: + SuperPacket(const uint32_t* header_ptr, int len); + + int length64() const; + int length32() const; + int fpgaid() const; + int nsamples() const; + int formatversion() const; + int length_for_sample(int isample); + + PolarfirePacket sample(int isample) const; +private: + const uint32_t* data_; + int length_; + int version_; +}; + +} +} + +#endif// pflib_decoding_PolarfirePacket_h + diff --git a/src/pflib/decoding/SuperPacket.cxx b/src/pflib/decoding/SuperPacket.cxx new file mode 100644 index 00000000..e3c78e92 --- /dev/null +++ b/src/pflib/decoding/SuperPacket.cxx @@ -0,0 +1,18 @@ +#include "pflib/decoding/SuperPacket.h" + +namespace pflib { +namespace decoding { + +SuperPacket::SuperPacket(const uint32_t* header_ptr, int len); + +int SuperPacket::length64() const; +int SuperPacket::length32() const; +int SuperPacket::fpgaid() const; +int SuperPacket::nsamples() const; +int SuperPacket::formatversion() const; +int SuperPacket::length_for_sample(int isample); + +PolarfirePacket SuperPacket::sample(int isample) const; + +} +} From 0809c56769e7977b99e6b177986e371d9a0a0a1b Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 16:57:52 +0200 Subject: [PATCH 27/37] Add two key functions --- include/pflib/decoding/SuperPacket.h | 2 +- src/pflib/decoding/SuperPacket.cxx | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/pflib/decoding/SuperPacket.h b/include/pflib/decoding/SuperPacket.h index d81d766f..d30060c8 100644 --- a/include/pflib/decoding/SuperPacket.h +++ b/include/pflib/decoding/SuperPacket.h @@ -17,7 +17,7 @@ class SuperPacket { int fpgaid() const; int nsamples() const; int formatversion() const; - int length_for_sample(int isample); + int length32_for_sample(int isample); PolarfirePacket sample(int isample) const; private: diff --git a/src/pflib/decoding/SuperPacket.cxx b/src/pflib/decoding/SuperPacket.cxx index e3c78e92..872b3a0e 100644 --- a/src/pflib/decoding/SuperPacket.cxx +++ b/src/pflib/decoding/SuperPacket.cxx @@ -3,16 +3,32 @@ namespace pflib { namespace decoding { -SuperPacket::SuperPacket(const uint32_t* header_ptr, int len); +SuperPacket::SuperPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len}{ + bool found_header=false; + while (len>0 && !found_header) { + if (*header_ptr==0xBEEF2021u) found_header=true; + len--; + header_ptr++; + } +} int SuperPacket::length64() const; int SuperPacket::length32() const; int SuperPacket::fpgaid() const; int SuperPacket::nsamples() const; int SuperPacket::formatversion() const; -int SuperPacket::length_for_sample(int isample); -PolarfirePacket SuperPacket::sample(int isample) const; +int SuperPacket::length32_for_sample(int isample) { + if (isample<0 || isample>=nsamples()) return 0; + return (data_[1+(isample/2)]>>(16*(isample%2)))&0xFFF; +} + +PolarfirePacket SuperPacket::sample(int isample) const { + int offset=1+((nsamples()+1)/2); + for (int i=0; i Date: Sat, 2 Apr 2022 16:59:10 +0200 Subject: [PATCH 28/37] Read superpacket headers --- include/pflib/decoding/SuperPacket.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/pflib/decoding/SuperPacket.h b/include/pflib/decoding/SuperPacket.h index d30060c8..595d44d5 100644 --- a/include/pflib/decoding/SuperPacket.h +++ b/include/pflib/decoding/SuperPacket.h @@ -14,10 +14,10 @@ class SuperPacket { int length64() const; int length32() const; - int fpgaid() const; - int nsamples() const; - int formatversion() const; - int length32_for_sample(int isample); + int fpgaid() const {if (length_ == 0) return -1; return (data_[0]>>20)&0xFF;} + int nsamples() const {if (length_ == 0) return -1; return (data_[0]>>16)&0xF;} + int formatversion() const {if (length_ == 0) return -1; return (data_[0]>>28)&0xF;} + int length_for_sample(int isample); PolarfirePacket sample(int isample) const; private: From a7ae4d28a33253b3735ad915b29462ab0dc6fb76 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 17:06:46 +0200 Subject: [PATCH 29/37] Correct compilation errors for superpacket header --- include/pflib/decoding/SuperPacket.h | 2 +- src/pflib/decoding/SuperPacket.cxx | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/pflib/decoding/SuperPacket.h b/include/pflib/decoding/SuperPacket.h index 595d44d5..2cacd9f9 100644 --- a/include/pflib/decoding/SuperPacket.h +++ b/include/pflib/decoding/SuperPacket.h @@ -17,7 +17,7 @@ class SuperPacket { int fpgaid() const {if (length_ == 0) return -1; return (data_[0]>>20)&0xFF;} int nsamples() const {if (length_ == 0) return -1; return (data_[0]>>16)&0xF;} int formatversion() const {if (length_ == 0) return -1; return (data_[0]>>28)&0xF;} - int length_for_sample(int isample); + int length32_for_sample(int isample) const; PolarfirePacket sample(int isample) const; private: diff --git a/src/pflib/decoding/SuperPacket.cxx b/src/pflib/decoding/SuperPacket.cxx index 872b3a0e..ecc71541 100644 --- a/src/pflib/decoding/SuperPacket.cxx +++ b/src/pflib/decoding/SuperPacket.cxx @@ -12,13 +12,9 @@ SuperPacket::SuperPacket(const uint32_t* header_ptr, int len) : data_{header_ptr } } -int SuperPacket::length64() const; -int SuperPacket::length32() const; -int SuperPacket::fpgaid() const; -int SuperPacket::nsamples() const; -int SuperPacket::formatversion() const; - -int SuperPacket::length32_for_sample(int isample) { +int SuperPacket::length64() const { return -1;} +int SuperPacket::length32() const { return -1;} +int SuperPacket::length32_for_sample(int isample) const { if (isample<0 || isample>=nsamples()) return 0; return (data_[1+(isample/2)]>>(16*(isample%2)))&0xFFF; } From bc39a85386fbfc2507daaddc10603a32ddddcf9b Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 17:01:13 +0200 Subject: [PATCH 30/37] Working on the tool --- tool/pftool.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tool/pftool.cc b/tool/pftool.cc index 38e5d714..35408844 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -992,6 +992,8 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { std::vector event = pft->daqReadEvent(); // here we decode the event and store the relevant information only... + pflib::decoding::SuperPacket data(&(event[0]),event.size()); + for (int ilink=0; ilinkhcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; From 6f4c2f5186778d7f20f0ad086ff9bb2f6701f465 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 17:11:19 +0200 Subject: [PATCH 31/37] I don't like this rebase crap --- tool/pftool.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 35408844..d5411550 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -27,6 +27,7 @@ #endif #include "Menu.h" #include "Rcfile.h" +#include "pflib/decoding/SuperPacket.h" /** * pull the target of our menu into this source file to reduce code @@ -993,7 +994,27 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { // here we decode the event and store the relevant information only... pflib::decoding::SuperPacket data(&(event[0]),event.size()); - + + /// debugging + if (ievt==0) { + FILE* f1=fopen("debug1.txt","w"); + for (int i=0; ihcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + for (int ic=0; ic<36; ic++) { + fprintf(f2,"%d %d ",ilink,ic); + for (int is=0; ishcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; From 62d369c6870d359726a958e7f91133e9fba4e82a Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 18:57:33 +0200 Subject: [PATCH 32/37] Various fixes required for working superscan --- include/pflib/decoding/RocPacket.h | 12 +++-- src/pflib/decoding/RocPacket.cxx | 13 +++++ src/pflib/decoding/SuperPacket.cxx | 11 ++-- tool/pfdecoder.cc | 2 +- tool/pftool.cc | 84 ++++++++++++++++++------------ 5 files changed, 78 insertions(+), 44 deletions(-) diff --git a/include/pflib/decoding/RocPacket.h b/include/pflib/decoding/RocPacket.h index 461134ed..638d562b 100644 --- a/include/pflib/decoding/RocPacket.h +++ b/include/pflib/decoding/RocPacket.h @@ -11,7 +11,7 @@ namespace decoding { */ class RocPacket { public: - RocPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { } + RocPacket(const uint32_t* header_ptr, int len); int rocid() const { if (length_==0) return -1; return (data_[0]>>16)&0xFFFF;} @@ -21,13 +21,15 @@ class RocPacket { int wadd() const { if (length_<3) return -1; return (data_[2]>>3)&0xFF;} - bool has_chan(int ichan) const { if (length_<2) return -1; if (ichan < 32) return (data_[1]>>ichan)&0x1; return (data_[0]>>(ichan-32))&0x1;} + bool has_chan(int ichan) const { return offset_to_chan(ichan)>=0; } - int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>20)&0x2FF;} + int get_tot(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>20)&0xFFF;} - int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>10)&0x2FF;} + int get_toa(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return (data_[offset]>>10)&0x3FF;} - int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x2FF;} + int get_adc(int ichan) const { int offset = offset_to_chan(ichan); if (offset == -1) return -1; return data_[offset]&0x3FF;} + + void dump() const; private: int offset_to_chan(int ichan) const; diff --git a/src/pflib/decoding/RocPacket.cxx b/src/pflib/decoding/RocPacket.cxx index 3a2aa779..e638a68c 100644 --- a/src/pflib/decoding/RocPacket.cxx +++ b/src/pflib/decoding/RocPacket.cxx @@ -1,8 +1,21 @@ #include "pflib/decoding/RocPacket.h" +#include namespace pflib { namespace decoding { +RocPacket::RocPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len} { + +} + +void RocPacket::dump() const { + for (int i=0; i=36) return -1; int offset=0; diff --git a/src/pflib/decoding/SuperPacket.cxx b/src/pflib/decoding/SuperPacket.cxx index ecc71541..b815911d 100644 --- a/src/pflib/decoding/SuperPacket.cxx +++ b/src/pflib/decoding/SuperPacket.cxx @@ -1,15 +1,16 @@ #include "pflib/decoding/SuperPacket.h" +#include namespace pflib { namespace decoding { SuperPacket::SuperPacket(const uint32_t* header_ptr, int len) : data_{header_ptr}, length_{len}{ bool found_header=false; - while (len>0 && !found_header) { - if (*header_ptr==0xBEEF2021u) found_header=true; - len--; - header_ptr++; - } + while (length_>0 && !found_header) { + if (*data_==0xBEEF2021u) found_header=true; + length_--; + data_++; + } } int SuperPacket::length64() const { return -1;} diff --git a/tool/pfdecoder.cc b/tool/pfdecoder.cc index 7240938d..3e42c68a 100644 --- a/tool/pfdecoder.cc +++ b/tool/pfdecoder.cc @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) { } if (verbosity>0) printf("\n"); - } else if (rel_super>2+(samples+1)/2 && rel_super<=2+8) { + } else if (rel_super>2+(samples+1)/2 && rel_super<=2+8 && fmt==2) { word_type=wt_junk; // empty sample words } else if (int(packet_pointers.size())>isample+1 && i==packet_pointers[isample+1]) { packet_header=i; diff --git a/tool/pftool.cc b/tool/pftool.cc index d5411550..267cb460 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -928,10 +928,14 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { // csv header csv_out <hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); } } + + printf(" Enabling IntCTest...\n"); + + for (int ilink=0; ilinkhcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + int iroc=ilink/2; + char pagename[32]; + snprintf(pagename,32,"REFERENCE_VOLTAGE_%d",(ilink%2)); + // set the value + pft->hcal.roc(iroc).applyParameter(pagename, "INTCTEST", 1); + if (cmd=="SCANCHARGE") { + snprintf(pagename,32,"DIGITAL_HALF_%d",(ilink%2)); + // set the value + pft->hcal.roc(iroc).applyParameter(pagename, "L1OFFSET", 8); + } + } + //////////////////////////////////////////////////////////// for (int step=0; stephcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 1); - // pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); + // pft->hcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 1); + pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 1); } ////////////////////////////////////////////////////////// /// Take the expected number of events and save the events for (int ievt=0; ievtbackend->fc_sendL1A(); + pft->backend->fc_calibpulse(); std::vector event = pft->daqReadEvent(); // here we decode the event and store the relevant information only... pflib::decoding::SuperPacket data(&(event[0]),event.size()); - /// debugging - if (ievt==0) { - FILE* f1=fopen("debug1.txt","w"); - for (int i=0; ihcal.elinks().nlinks(); ilink++) { - if (!pft->hcal.elinks().isActive(ilink)) continue; - for (int ic=0; ic<36; ic++) { - fprintf(f2,"%d %d ",ilink,ic); - for (int is=0; ishcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; csv_out << value << ',' << ilink << ',' << ichan << ',' << ievt; - for (int i=0; ihcal.elinks().nlinks(); ilink++) { if (!pft->hcal.elinks().isActive(ilink)) continue; @@ -1040,10 +1047,21 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { } ////////////////////////////////////////////////////////// - } - //////////////////////////////////////////////////////////// } + + printf(" Diabling IntCTest...\n"); + + for (int ilink=0; ilinkhcal.elinks().nlinks(); ilink++) { + if (!pft->hcal.elinks().isActive(ilink)) continue; + + int iroc=ilink/2; + char pagename[32]; + snprintf(pagename,32,"REFERENCE_VOLTAGE_%d",(ilink%2)); + // set the value + pft->hcal.roc(iroc).applyParameter(pagename, "INTCTEST", 0); + } + //////////////////////////////////////////////////////////// } } From e59041332eb20b7005ee99991233a4384b8202c0 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 15:56:34 +0200 Subject: [PATCH 33/37] Separated the bitlip loop into its own function --- include/pflib/PolarfireTarget.h | 2 ++ src/pflib/PolarfireTarget.cxx | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/pflib/PolarfireTarget.h b/include/pflib/PolarfireTarget.h index 36318ae3..27e8e5ae 100644 --- a/include/pflib/PolarfireTarget.h +++ b/include/pflib/PolarfireTarget.h @@ -216,6 +216,8 @@ struct PolarfireTarget { /** Carries out the standard elink alignment process */ void elink_relink(int verbosity); + + void bitslip(); private: int samples_per_event_; diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index e6a0a12a..b17e4ff8 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -454,13 +454,19 @@ void PolarfireTarget::elink_relink(int verbosity) { if (verbosity>0) { printf("...Hard reset\n"); } - elinks.resetHard(); - sleep(1); + //elinks.resetHard(); + //sleep(1); if (verbosity>0) { printf("...Scanning bitslip values\n"); } + bitslip(); + +} + +void PolarfireTarget::bitslip(){ + pflib::Elinks& elinks=hcal.elinks(); for (int ilink=0; ilink Date: Sat, 2 Apr 2022 16:43:46 +0200 Subject: [PATCH 34/37] Made loop over delays which stops when bitslip loop is satisfied for each delay value --- include/pflib/PolarfireTarget.h | 6 ++- src/pflib/PolarfireTarget.cxx | 80 ++++++++++++++++----------------- tool/pftool.cc | 6 ++- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/include/pflib/PolarfireTarget.h b/include/pflib/PolarfireTarget.h index 27e8e5ae..57d2a0ce 100644 --- a/include/pflib/PolarfireTarget.h +++ b/include/pflib/PolarfireTarget.h @@ -215,9 +215,11 @@ struct PolarfireTarget { bool loadBiasSettings(const std::string& file_name); /** Carries out the standard elink alignment process */ - void elink_relink(int verbosity); + void elink_relink(int ilink,int verbosity); - void bitslip(); + void delay_loop(int ilink); + + bool bitslip_loop(int ilink); private: int samples_per_event_; diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index b17e4ff8..c11d1fc7 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -441,61 +441,59 @@ bool PolarfireTarget::loadBiasSettings(const std::string& file_name) { } } -void PolarfireTarget::elink_relink(int verbosity) { +void PolarfireTarget::elink_relink(int ilink ,int verbosity) { pflib::Elinks& elinks=hcal.elinks(); - if (verbosity>0) - printf("...Setting phase delays\n"); - for (int ilink=0; ilink0) { - printf("...Hard reset\n"); - } - //elinks.resetHard(); - //sleep(1); - - if (verbosity>0) { - printf("...Scanning bitslip values\n"); - } +} - bitslip(); +void PolarfireTarget::delay_loop(int ilink){ + pflib::Elinks& elinks=hcal.elinks(); + if (elinks.isActive(ilink)){ + for (int delay=20; delay<26; delay++){ + elinks.setDelay(ilink,delay); + if (bitslip_loop(ilink)) break; + } + } } -void PolarfireTarget::bitslip(){ +bool PolarfireTarget::bitslip_loop(int ilink){ pflib::Elinks& elinks=hcal.elinks(); - for (int ilink=0; ilink spy=elinks.spy(ilink); - for (size_t i=0; i+4 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]); } - + int imax=-1; + for (int slip=0; slip<8; slip++) { + if (imax<0 || okcount[slip]>okcount[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; + } + else return false; + } + +//} diff --git a/tool/pftool.cc b/tool/pftool.cc index 523ae83e..65de12d0 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -240,8 +240,10 @@ 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; - if (cmd=="RELINK") - pft->elink_relink(2); + if (cmd=="RELINK"){ + ilink=BaseMenu::readline_int("Which elink? ",ilink); + pft->elink_relink(ilink,2); + } if (cmd=="SPY") { ilink=BaseMenu::readline_int("Which elink? ",ilink); std::vector spy=elinks.spy(ilink); From d7c0f03bbeb744bc757b3269cca7bf5836cc3b18 Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sat, 2 Apr 2022 17:21:29 +0200 Subject: [PATCH 35/37] Added option to relink specific elink or all --- src/pflib/PolarfireTarget.cxx | 16 +++++++++++----- tool/pftool.cc | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pflib/PolarfireTarget.cxx b/src/pflib/PolarfireTarget.cxx index c11d1fc7..01318c4f 100644 --- a/src/pflib/PolarfireTarget.cxx +++ b/src/pflib/PolarfireTarget.cxx @@ -444,19 +444,25 @@ bool PolarfireTarget::loadBiasSettings(const std::string& file_name) { void PolarfireTarget::elink_relink(int ilink ,int verbosity) { pflib::Elinks& elinks=hcal.elinks(); - delay_loop(ilink); + if (ilink == -1){ + for (int ilink=0; ilinkhcal.elinks(); static int ilink=0; if (cmd=="RELINK"){ - ilink=BaseMenu::readline_int("Which elink? ",ilink); + ilink=BaseMenu::readline_int("Which elink? (-1 for all) ",ilink); pft->elink_relink(ilink,2); } if (cmd=="SPY") { From 3535e4aff9740b53587bed3a2264adf3126eb66e Mon Sep 17 00:00:00 2001 From: Erik Wallin Date: Sun, 3 Apr 2022 16:10:41 +0200 Subject: [PATCH 36/37] Add ability to choose high range or low range --- tool/pftool.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index c07c8d2f..0890266d 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -844,6 +844,7 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { daq_run(cmd,run,nevents,rate,fname); } } + /** Deprecated by new TASK menu */ if (cmd=="SCAN"){ std::string pagename=BaseMenu::readline("Sub-block (aka Page) name : "); std::string valuename=BaseMenu::readline("Value (aka Parameter) name : "); @@ -897,6 +898,7 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { static int events_per_step=100; std::string pagetemplate; std::string valuename; + std::string modeinfo; int nsamples=1; { @@ -917,8 +919,12 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { if (cmd=="SCANCHARGE") { valuename="CALIB_DAC"; pagetemplate="REFERENCE_VOLTAGE_%d"; + printf("CALIB_DAC valid range is 0...4095\n"); low_value=BaseMenu::readline_int("Smallest value of CALIB_DAC?",low_value); - high_value=BaseMenu::readline_int("Largest value of CALIB_DAC?",high_value); + high_value=BaseMenu::readline_int("Largest value of CALIB_DAC?",high_value); + bool is_high_range=BaseMenu::readline_bool("Use HighRange? ",false); + if (is_high_range) modeinfo="HIGHRANGE"; + else modeinfo="LOWRANGE"; } /// common stuff for all scans if (cmd=="SCANCHARGE") { @@ -1014,8 +1020,7 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { char pagename[32]; snprintf(pagename,32,"CHANNEL_%d",(ilink%2)*(NUM_ELINK_CHAN)+ichan); // set the value - // pft->hcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 1); - pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 1); + pft->hcal.roc(iroc).applyParameter(pagename, modeinfo, 1); } ////////////////////////////////////////////////////////// @@ -1053,8 +1058,7 @@ static void tasks( const std::string& cmd, PolarfireTarget* pft ) { char pagename[32]; snprintf(pagename,32,"CHANNEL_%d",(ilink%2)*(NUM_ELINK_CHAN)+ichan); // set the value - pft->hcal.roc(iroc).applyParameter(pagename, "LOWRANGE", 0); - // pft->hcal.roc(iroc).applyParameter(pagename, "HIGHRANGE", 0); + pft->hcal.roc(iroc).applyParameter(pagename, modeinfo, 0); } ////////////////////////////////////////////////////////// From 5b1bb35c8de6d902fc31c1df879b21e43db5c24a Mon Sep 17 00:00:00 2001 From: desk-fish Date: Sun, 3 Apr 2022 22:24:21 +0200 Subject: [PATCH 37/37] Fixed issues with DMA being unable to write files --- tool/pftool.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tool/pftool.cc b/tool/pftool.cc index 0890266d..d183db6e 100644 --- a/tool/pftool.cc +++ b/tool/pftool.cc @@ -765,11 +765,7 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { pft->prepareNewRun(); // start DMA, if that's what we're doing... - if (dma_enabled && !start_dma_cmd.empty()) { - printf("Launching DMA...\n"); - std::string cmd=start_dma_cmd+" "+fname; - system(cmd.c_str()); - } + if (dma_enabled) rwbi->daq_dma_dest(fname); // enable external triggers pft->backend->fc_enables(true,true,false); @@ -808,11 +804,7 @@ static void daq( const std::string& cmd, PolarfireTarget* pft ) { if (f) fclose(f); - if (dma_enabled && !stop_dma_cmd.empty()) { - printf("Stopping DMA...\n"); - std::string cmd=stop_dma_cmd; - system(cmd.c_str()); - } + if (dma_enabled) rwbi->daq_dma_close(); } if (cmd=="PEDESTAL" || cmd=="CHARGE") {