Skip to content

Commit

Permalink
add header_check to elinks menu
Browse files Browse the repository at this point in the history
simple pedestal run and count good/bad bx headers and idles
  • Loading branch information
tomeichlersmith committed Apr 7, 2022
1 parent 055d136 commit fe39f59
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/pflib/decoding/RocPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class RocPacket {

int wadd() const { if (length_<3) return -1; return (data_[2]>>3)&0xFF;}

int length() const { return length_; }

bool good_bxheader() const { if (length_<3) return false; return (data_[2]&0xff000000)==0xaa000000; }

bool good_idle() const { if (length_<42) return false; return data_[41]==0xaccccccc; }

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)&0xFFF;}
Expand Down
54 changes: 53 additions & 1 deletion tool/pftool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ static void link( const std::string& cmd, PolarfireTarget* pft ) {
* ## Commands
* - RELINK : pflib::PolarfireTarget::elink_relink
* - SPY : pflib::Elinks::spy
* - HEADER_CHECK : do a pedestal run and count good/bad headers in it
* - BITSLIP : pflib::Elinks::setBitslip and pflib::Elinks::setBitslipAuto
* - BIGSPY : PolarfireTarget::elinksBigSpy
* - DELAY : pflib::Elinks::setDelay
Expand All @@ -239,7 +240,7 @@ 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 ilink=0,nevents{100};
static int min_delay{0}, max_delay{128};
if (cmd=="RELINK"){
ilink=BaseMenu::readline_int("Which elink? (-1 for all) ",ilink);
Expand All @@ -253,6 +254,56 @@ static void elinks( const std::string& cmd, PolarfireTarget* pft ) {
for (size_t i=0; i<spy.size(); i++)
printf("%02d %05x\n",int(i),spy[i]);
}
if (cmd=="HEADER_CHECK") {
nevents=BaseMenu::readline_int("Num events? ",nevents);

int nsamples=1;
{
bool multi;
int nextra;
pft->hcal.fc().getMultisampleSetup(multi,nextra);
if (multi) nsamples=nextra+1;
}

pft->prepareNewRun();

int n_good_bxheaders[8] = {0,0,0,0,0,0,0,0};
int n_bad_bxheaders[8] = {0,0,0,0,0,0,0,0};
int n_good_idles[8] = {0,0,0,0,0,0,0,0};
int n_bad_idles[8] = {0,0,0,0,0,0,0,0};
for (int ievt{0}; ievt < nevents; ievt++) {
pft->backend->fc_sendL1A();
std::vector<uint32_t> event_raw = pft->daqReadEvent();
pflib::decoding::SuperPacket event{&(event_raw[0]), event_raw.size()};
for (int s{0}; s < nsamples; s++) {
for (int l{0}; l < 8; l++) {
auto packet = event.sample(s).roc(l);
if (packet.length() > 2) {
if (event.sample(s).roc(l).good_bxheader()) n_good_bxheaders[l]++;
else n_bad_bxheaders[l]++;
if (event.sample(s).roc(l).good_idle()) n_good_idles[l]++;
else n_bad_idles[l]++;
}
}
}
}

printf(" %26s | %26s\n","BX Headers","Idles");
printf("Link %10s %10s %4s | %10s %10s %4s\n","Good","Bad","B/T","Good","Bad","B/T");
for (int ilink{0}; ilink < 8; ilink++) {
float bg_bxheaders = 0.;
if (n_good_bxheaders[ilink]+n_bad_bxheaders[ilink]>0)
bg_bxheaders = float(n_bad_bxheaders[ilink])/
(n_good_bxheaders[ilink]+n_bad_bxheaders[ilink]);
float bg_idles = 0.;
if (n_good_idles[ilink]+n_bad_idles[ilink]>0)
bg_idles = float(n_bad_idles[ilink])/
(n_good_idles[ilink]+n_bad_idles[ilink]);
printf("%4d %10d %10d %.2f | %10d %10d %.2f\n", ilink,
n_good_bxheaders[ilink], n_bad_bxheaders[ilink], bg_bxheaders,
n_good_idles[ilink], n_bad_idles[ilink], bg_idles);
}
}
if (cmd=="BITSLIP") {
ilink=BaseMenu::readline_int("Which elink? ",ilink);
int bitslip=BaseMenu::readline_int("Bitslip value (-1 for auto): ",elinks.getBitslip(ilink));
Expand Down Expand Up @@ -1348,6 +1399,7 @@ static void RunMenu( PolarfireTarget* pft_ ) {
pfMenu::Line("HARD_RESET","Hard reset of the PLL", &elinks),
pfMenu::Line("STATUS", "Elink status summary", &elinks ),
pfMenu::Line("SPY", "Spy on an elink", &elinks ),
pfMenu::Line("HEADER_CHECK", "Do a pedestal run and tally good/bad headers, only non-DMA", &elinks),
pfMenu::Line("BITSLIP", "Set the bitslip for a link or turn on auto", &elinks),
pfMenu::Line("SCAN", "Scan on an elink", &elinks ),
pfMenu::Line("DELAY", "Set the delay on an elink", &elinks),
Expand Down

0 comments on commit fe39f59

Please sign in to comment.