#include "roc/BoardsVector.h" #include "dabc/Manager.h" #include "dabc/Command.h" #include "roc/Commands.h" #include "roc/Gpio.h" #include "nxyter/RocNx.h" #include "roc/defines_roc.h" #include "feet/defines_feet.h" void roc::BoardsVector::addRoc(const std::string& roc, const std::string& febs) { BoardRec rec(0); rec.rocname = roc; rec.febskind = febs; push_back(rec); } bool roc::BoardsVector::setBoard(unsigned n, roc::Board* brd, std::string devname) { if ((brd==0) || (n>=size())) return false; BoardRec& rec = at(n); rec.brd = brd; rec.devname = devname; if ((rec.febskind=="Get4") || (rec.febskind=="GET4")) { DOUT0(("Configure Get4 for board%u", n)); rec.get4 = true; } else if (rec.febskind.length()>0) { std::string feb0kind, feb1kind; unsigned pos = rec.febskind.find(","); if (pos == std::string::npos) { feb0kind = rec.febskind; } else { feb0kind = rec.febskind.substr(0, pos); feb1kind = rec.febskind.substr(pos+1, rec.febskind.length()-pos); } // DOUT0(("kind0 = %s kind1 = %s", feb0kind.c_str(), feb1kind.c_str())); if (feb0kind.length()>0) { int kind = nxyter::FebBase::stringToType(feb0kind.c_str()); rec.feb0 = nxyter::FebBase::newFeb(brd, 0, kind); DOUT0(("FEB0 kind = %d feb0 = %p", kind, rec.feb0)); } if (feb1kind.length()>0) { int kind = nxyter::FebBase::stringToType(feb1kind.c_str()); rec.feb1 = nxyter::FebBase::newFeb(brd, 1, kind); DOUT0(("FEB1 kind = %d feb1 = %p", kind, rec.feb1)); } } // setup AUX2 if (rec.feb0 || rec.feb1) { roc::Gpio gpio(brd); gpio.getConfig(rec.gpio_mask_save); bool riseedge, falledge, throttled, extrafunc, altin; roc::Gpio::unpackConfig(rec.gpio_mask_save, 6, riseedge, falledge, throttled, extrafunc, altin); extrafunc = true; altin = true; rec.gpio_mask_on = rec.gpio_mask_save; roc::Gpio::packConfig(rec.gpio_mask_on, 6, riseedge, falledge, throttled, extrafunc, altin); extrafunc = false; altin = false; rec.gpio_mask_off = rec.gpio_mask_save; roc::Gpio::packConfig(rec.gpio_mask_off, 6, riseedge, falledge, throttled, extrafunc, altin); // setup test pulse generator nxyter::RocNx rocnx(brd); int32_t period = 250000; // 1 khz rocnx.fireTestPulse(period, 128, 0); // DOUT0(("************ Fire test pulses for ROC ****************")); } return true; }; bool roc::BoardsVector::isAnyGet4() { for (unsigned n=0;noperGen(lst); } } void roc::BoardsVector::returnBoards() { for (unsigned n=0;n=size()) return 0; nxyter::FebBase* feb = 0; if (nfeb==0) feb = at(n).feb0; else if (nfeb==1) feb = at(n).feb1; return feb ? feb->getNumMonAdc() : 0; } void roc::BoardsVector::readFeb(uint32_t rocid, uint32_t febid, nxyter::FebBase* feb, MessagesVector* vect) { if ((feb==0) || !feb->monAdcSupport()) return; roc::Message msg; // static uint16_t adccnt = 0; for (int nch=0;nchgetNumMonAdc(); nch++) { uint16_t val = 0; if (feb->getMonAdc(nch, val)!=0) continue; // just to exclude real readings // val = (adccnt++) & 0xfff; // DOUT0(("READ ADC roc %u feb %u adc %u value %u", rocid, febid, nch, val)); msg.reset(); msg.setMessageType(roc::MSG_SYS); msg.setRocNumber(rocid); msg.setSysMesType(roc::SYSMSG_ADC); msg.setSysMesData((febid << 31) | (nch << 24) | val); vect->push_back(msg); } } roc::MessagesVector* roc::BoardsVector::readoutExtraMessages() { if (size()==0) return 0; roc::MessagesVector* vect = new roc::MessagesVector; DOUT5(("Readout extra messages")); roc::Message msg; for (unsigned n=0;nrocNumber(); msg.reset(); msg.setMessageType(roc::MSG_SYS); msg.setRocNumber(rocid); msg.setSysMesType(roc::SYSMSG_PCTIME); msg.setSysMesData((uint32_t) time(NULL)); vect->push_back(msg); readFeb(rocid, 0, at(n).feb0, vect); readFeb(rocid, 1, at(n).feb1, vect); } return vect; } void roc::BoardsVector::autoped_issue_system_message(roc::Board* brd, uint32_t type) { if (brd==0) return; // brd->operPPP(ROC_NX_FIFO_RESET, 1, // and flush fifo // ROC_NX_FIFO_RESET, 0, // ROC_ADDSYSMSG, type ); // insert sysmsg brd->put(ROC_ADDSYSMSG, type); } void roc::BoardsVector::autoped_setnxmode(nxyter::FebBase* feb, bool testtrig) { if (feb==0) return; for (int i=0; inumNx(); i++) { if (feb->getNxOffline(i)) continue; // skip of offline feb->nx(i).i2c().setTestModes(false, testtrig, 0); } } // #include void roc::BoardsVector::autoped_switch(bool switch_on) { for (unsigned nbrd=0; nbrd2 && switch_on) { // DOUT0(("EMERGENCY EXIT")); // exit(6); // } } void roc::BoardsVector::issueDLM(int code) { for (unsigned n=0;n