• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

plugin/src/BoardsVector.cxx (r4864/r4162)

Go to the documentation of this file.
00001 #include "roc/BoardsVector.h"
00002 
00003 #include "dabc/Manager.h"
00004 #include "dabc/Command.h"
00005 
00006 #include "roc/Commands.h"
00007 #include "base/Gpio.h"
00008 #include "nxyter/RocNx.h"
00009 
00010 #include "roc/defines_roc.h"
00011 #include "feet/defines_feet.h"
00012 
00013 void roc::BoardsVector::addRoc(const std::string& roc, const std::string& febs)
00014 {
00015    BoardRec rec(0);
00016    rec.rocname = roc;
00017    rec.febskind = febs;
00018 
00019    push_back(rec);
00020 }
00021 
00022 bool roc::BoardsVector::setBoard(unsigned n, roc::Board* brd, std::string devname)
00023 {
00024    if ((brd==0) || (n>=size())) return false;
00025 
00026    BoardRec& rec = at(n);
00027    
00028    rec.brd = brd;
00029    rec.devname = devname;
00030 
00031    if ((rec.febskind=="Get4") || (rec.febskind=="GET4")) {
00032       DOUT0(("Configure Get4 for board%u", n));
00033       rec.get4 = true;
00034    } else
00035 
00036    if (rec.febskind.length()>0) {
00037       std::string feb0kind, feb1kind;
00038 
00039       unsigned pos = rec.febskind.find(",");
00040       if (pos == std::string::npos) {
00041          feb0kind = rec.febskind;
00042       } else {
00043          feb0kind = rec.febskind.substr(0, pos);
00044          feb1kind = rec.febskind.substr(pos+1, rec.febskind.length()-pos);
00045       }
00046       
00047 //      DOUT0(("kind0 = %s kind1 = %s", feb0kind.c_str(), feb1kind.c_str()));
00048 
00049       if (feb0kind.length()>0) {
00050          int kind = nxyter::FebBase::stringToType(feb0kind.c_str());
00051          rec.feb0 = nxyter::FebBase::newFeb(brd, 0, kind);
00052          DOUT0(("FEB0 kind = %d feb0 = %p", kind, rec.feb0));
00053       }
00054 
00055       if (feb1kind.length()>0) {
00056          int kind = nxyter::FebBase::stringToType(feb1kind.c_str());
00057          rec.feb1 = nxyter::FebBase::newFeb(brd, 1, kind);
00058          DOUT0(("FEB1 kind = %d feb1 = %p", kind, rec.feb1));
00059       }
00060    }
00061 
00062 
00063    // setup AUX2
00064 
00065    if (rec.feb0 || rec.feb1) {
00066 
00067       base::Gpio gpio(brd);
00068 
00069       gpio.getConfig(rec.gpio_mask_save);
00070       bool riseedge, falledge, throttled, extrafunc, altin;
00071       base::Gpio::unpackConfig(rec.gpio_mask_save, 6,
00072             riseedge, falledge, throttled, extrafunc, altin);
00073 
00074       extrafunc = true;
00075       altin     = true;
00076       rec.gpio_mask_on = rec.gpio_mask_save;
00077       base::Gpio::packConfig(rec.gpio_mask_on, 6,
00078             riseedge, falledge, throttled, extrafunc, altin);
00079 
00080       extrafunc = false;
00081       altin     = false;
00082       rec.gpio_mask_off = rec.gpio_mask_save;
00083       base::Gpio::packConfig(rec.gpio_mask_off, 6,
00084             riseedge, falledge, throttled, extrafunc, altin);
00085 
00086       // setup test pulse generator
00087       nxyter::RocNx rocnx(brd);
00088       int32_t period = 250000;              // 1 khz
00089       rocnx.fireTestPulse(period, 128, 0);
00090 
00091 //      DOUT0(("************ Fire test pulses for ROC  ****************"));
00092    }
00093 
00094    return true;
00095 };
00096 
00097 bool roc::BoardsVector::isAnyGet4()
00098 {
00099    for (unsigned n=0;n<size();n++)
00100       if (at(n).get4) return true;
00101    return false;
00102 }
00103 
00104 void roc::BoardsVector::ResetAllGet4()
00105 {
00106    DOUT0(("Getting into reset !!!"));
00107 
00108    for (unsigned n=0;n<size();n++)
00109       if (at(n).get4 && at(n).brd) {
00110          DOUT0(("Call GET4 reset for board %p", at(n).brd));
00111 
00112          base::OperList lst;
00113 
00114 /*
00115          lst.addPut(ROC_ADDSYSMSG, SYSMSG_USER_RECONFIGURE);
00116          
00117          lst.addPut(0x510000,0x0);
00118          lst.addPut(0x510000,0x10);
00119          // get4 chip enabling
00120          lst.addPut(0x501000,0x00ff);
00121          // sampling
00122          lst.addPut(0x500200,0x07aa);
00123          // enable 250 MHz clock
00124          lst.addPut(0x500204,0x1);
00125          // reset of Get4 
00126          lst.addPut(0x500014,0x1);
00127          lst.addPut(0x500014,0x0);
00128 */ 
00129           
00130          lst.addPut(ROC_ADDSYSMSG, SYSMSG_USER_RECONFIGURE);
00131          lst.addPut(ROC_FEET_TRANSMIT_MASK,0xFF);   // set transmit mask
00132          lst.addPut(ROC_FEET_CMD_TO_FEET,0x8);    // ro-rst
00133 
00134 
00135          at(n).brd->operGen(lst);
00136       }
00137 }
00138 
00139 
00140 void roc::BoardsVector::returnBoards()
00141 {
00142    for (unsigned n=0;n<size();n++) {
00143 
00144       if (at(n).brd == 0) continue;
00145       
00146       if (at(n).feb0 || at(n).feb1) {
00147          base::Gpio gpio(at(n).brd);
00148          gpio.setConfig(at(n).gpio_mask_save);
00149 
00150          nxyter::RocNx rocnx(at(n).brd);
00151 
00152          // stop test pulse generator
00153          rocnx.fireTestPulse(0, 0, 0);
00154       }
00155 
00156       delete at(n).feb0;
00157 
00158       delete at(n).feb1;
00159 
00160       roc::CmdReturnBoardPtr cmd;
00161       cmd.SetPtr(roc::CmdReturnBoardPtr::Board(), at(n).brd);
00162       cmd.SetReceiver(at(n).devname.c_str());
00163       dabc::mgr.Execute(cmd);
00164    }
00165    clear();
00166    
00167    fDLMDevs.clear();
00168 }
00169 
00170 int roc::BoardsVector::numAdc(unsigned n, unsigned nfeb)
00171 {
00172    if (n>=size()) return 0;
00173    nxyter::FebBase* feb = 0;
00174    if (nfeb==0) feb = at(n).feb0; else
00175    if (nfeb==1) feb = at(n).feb1;
00176    return feb ? feb->getNumMonAdc() : 0;
00177 }
00178 
00179 
00180 void roc::BoardsVector::readFeb(uint32_t rocid, uint32_t febid, nxyter::FebBase* feb, MessagesVector* vect)
00181 {
00182    if ((feb==0) || !feb->monAdcSupport()) return;
00183 
00184    roc::Message msg;
00185 
00186 //   static uint16_t adccnt = 0;
00187 
00188    for (int nch=0;nch<feb->getNumMonAdc(); nch++) {
00189       uint16_t val = 0;
00190 
00191       if (feb->getMonAdc(nch, val)!=0) continue;
00192 
00193       // just to exclude real readings
00194       // val = (adccnt++) & 0xfff;
00195 
00196 //      DOUT0(("READ ADC roc %u feb %u adc %u value %u", rocid, febid, nch, val));
00197 
00198       msg.reset();
00199       msg.setMessageType(roc::MSG_SYS);
00200       msg.setRocNumber(rocid);
00201       msg.setSysMesType(roc::SYSMSG_ADC);
00202       msg.setSysMesData((febid << 31) | (nch << 24) | val);
00203       vect->push_back(msg);
00204    }
00205 }
00206 
00207 roc::MessagesVector* roc::BoardsVector::readoutExtraMessages()
00208 {
00209    if (size()==0) return 0;
00210 
00211    roc::MessagesVector* vect = new roc::MessagesVector;
00212 
00213    DOUT5(("Readout extra messages"));
00214 
00215    roc::Message msg;
00216 
00217    for (unsigned n=0;n<size();n++) {
00218 
00219       if (at(n).brd == 0) continue;
00220 
00221       uint32_t rocid = at(n).brd->rocNumber();
00222 
00223       msg.reset();
00224       msg.setMessageType(roc::MSG_SYS);
00225       msg.setRocNumber(rocid);
00226       msg.setSysMesType(roc::SYSMSG_PCTIME);
00227       msg.setSysMesData((uint32_t) time(NULL));
00228       vect->push_back(msg);
00229 
00230       readFeb(rocid, 0, at(n).feb0, vect);
00231 
00232       readFeb(rocid, 1, at(n).feb1, vect);
00233    }
00234 
00235    return vect;
00236 }
00237 
00238 void roc::BoardsVector::autoped_issue_system_message(roc::Board* brd, uint32_t type)
00239 {
00240    if (brd==0) return;
00241 //   brd->operPPP(ROC_NX_FIFO_RESET, 1,   // and flush fifo
00242 //                ROC_NX_FIFO_RESET, 0,
00243 //                ROC_ADDSYSMSG, type ); // insert sysmsg
00244    brd->put(ROC_ADDSYSMSG, type);
00245 }
00246 
00247 void roc::BoardsVector::produceSystemMessage(uint32_t id)
00248 {
00249    for (unsigned n=0;n<size();n++) {
00250       if (at(n).brd)
00251          at(n).brd->put(ROC_ADDSYSMSG, id);
00252    }
00253 }
00254 
00255 
00256 void roc::BoardsVector::autoped_setnxmode(nxyter::FebBase* feb, bool testtrig)
00257 {
00258    if (feb==0) return;
00259 
00260    for (int i=0; i<feb->numNx(); i++) {
00261       if (feb->getNxOffline(i)) continue; // skip of offline
00262       feb->nx(i).i2c().setTestModes(false, testtrig, 0);
00263    }
00264 }
00265 
00266 // #include <stdlib.h>
00267 
00268 void roc::BoardsVector::autoped_switch(bool switch_on)
00269 {
00270    for (unsigned nbrd=0; nbrd<size(); nbrd++) {
00271       if (at(nbrd).brd==0) continue;
00272 
00273       if ((at(nbrd).feb0==0) && (at(nbrd).feb1==0)) continue;
00274 
00275       DOUT1(("Brd %p switch autoped %s", at(nbrd).brd, DBOOL(switch_on)));
00276 
00277       base::Gpio gpio(at(nbrd).brd);
00278       nxyter::RocNx rocnx(at(nbrd).brd);
00279 
00280       if (switch_on) {
00281          autoped_issue_system_message(at(nbrd).brd, roc::SYSMSG_USER_RECONFIGURE);
00282          rocnx.fireTestPulse(250000, 128, 0); // 1 khz, 500 ns
00283          autoped_setnxmode(at(nbrd).feb0, true);
00284          autoped_setnxmode(at(nbrd).feb1, true);
00285          gpio.setConfig(at(nbrd).gpio_mask_on);
00286          autoped_issue_system_message(at(nbrd).brd, roc::SYSMSG_USER_CALIBR_ON);
00287       } else {
00288          autoped_issue_system_message(at(nbrd).brd, roc::SYSMSG_USER_RECONFIGURE);
00289          rocnx.fireTestPulse(0, 0, 0); // disable
00290          gpio.setConfig(at(nbrd).gpio_mask_off);
00291          autoped_setnxmode(at(nbrd).feb0, false);
00292          autoped_setnxmode(at(nbrd).feb1, false);
00293          autoped_issue_system_message(at(nbrd).brd, roc::SYSMSG_USER_CALIBR_OFF);
00294       }
00295    }
00296    
00297 //   static int cnt = 0;
00298 //   if (cnt++>2 && switch_on) {
00299 //      DOUT0(("EMERGENCY EXIT"));
00300 //      exit(6);
00301 //   }
00302 }
00303 
00304 void roc::BoardsVector::issueDLM(int code)
00305 {
00306    for (unsigned n=0;n<fDLMDevs.size();n++) {
00307       roc::CmdDLM cmd(code);
00308 
00309       cmd.SetReceiver(fDLMDevs[n]);
00310 
00311       dabc::mgr.Submit(cmd);
00312    }
00313 }
00314 

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1