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

roclib/src_roc/Board.cxx (r4864/r4162)

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <stdio.h>
00003 
00004 #include <iostream>
00005 #include <string>
00006 #include <vector>
00007 
00008 #include "base/Url.h"
00009 
00010 #include "roc/Board.h"
00011 #include "roc/defines_roc.h"
00012 #include "roc/defines_optic.h"
00013 #include "roc/defines_udp.h"
00014 #include "feet/defines_feet.h"
00015 
00016 const char* roc::xmlRocPool         = "RocPool";
00017 const char* roc::xmlTransportWindow = "TransportWindow";
00018 const char* roc::xmlTransportKind   = "TransportKind";
00019 const char* roc::xmlBoardAddr       = "BoardAddr";
00020 const char* roc::xmlRole            = "Role";
00021 const char* roc::xmlRocNumber       = "RocNumber";
00022 const char* roc::xmlLowWater        = "LowWater";
00023 const char* roc::xmlHighWater       = "HighWater";
00024 const char* roc::xmlMsgFormat       = "MsgFormat";
00025 const char* roc::xmlFlushTime       = "FlushTime";
00026 
00027 const char* roc::typeUdpDevice      = "roc::UdpDevice";
00028 const char* roc::typeAbbDevice      = "roc::AbbDevice";
00029 
00030 
00077 //----------------------------------------------------------------------------
00078 
00079 roc::Board::Board() :
00080    base::Board()
00081 {
00082 
00083   // current ROC address def's from defines.h
00084 
00085   addRegAddrMapping("ROC_TYPE", ROC_TYPE);
00086   addRegAddrMapping("ROC_HWV", ROC_HWV);
00087   addRegAddrMapping("ROC_ROCID", ROC_ROCID);
00088   addRegAddrMapping("ROC_ADDSYSMSG", ROC_ADDSYSMSG);
00089   addRegAddrMapping("ROC_SYSTEM_RESET", ROC_SYSTEM_RESET);
00090 }
00091 
00092 //----------------------------------------------------------------------------
00093 
00094 roc::Board::~Board()
00095 {
00096 }
00097 
00098 //----------------------------------------------------------------------------
00100 
00101 uint32_t roc::Board::getRocFpgaType()
00102 {
00103    uint32_t num = 0;
00104    get(ROC_FPGA_TYPE, num);
00105    return num;
00106 }
00107 
00108 //----------------------------------------------------------------------------
00110 
00111 uint32_t roc::Board::getRocSvnRev()
00112 {
00113    uint32_t num = 0;
00114    get(ROC_SVN_REVISION, num);
00115    return num;
00116 }
00117 
00118 //----------------------------------------------------------------------------
00120 
00124 uint32_t roc::Board::getRocBuildTime()
00125 {
00126    uint32_t num = 0;
00127    get(ROC_BUILD_TIME, num);
00128    return num;
00129 }
00130 
00131 //----------------------------------------------------------------------------
00133 
00138 int roc::Board::uploadCommandsList(unsigned num, const base::OperList& lst, double tmout)
00139 {
00140    if (num >= ROC_CMD_LST_NUMBER) {
00141       Debug(-1, "Wrong number %u of commands list", num);
00142       return ROC_ADDRESS_ERROR;
00143    }
00144 
00145    base::OperList setlst;
00146 
00147    unsigned addr = ROC_CMD_LST_MEM + num * ROC_CMD_LST_SIZE / ROC_CMD_LST_NUMBER;
00148 
00149    for (int n=0;n<lst.number();n++) {
00150       if (!lst.isput(n)) {
00151          Debug(-1, "Only PUT operations are supported by commands list");
00152          return ROC_VALUE_ERROR;
00153       }
00154 
00155       if (addr >= ROC_CMD_LST_MEM + ROC_CMD_LST_SIZE) {
00156          Debug(-1, "Commands list to long %d for slot %u", lst.number(), num);
00157          return ROC_VALUE_ERROR;
00158       }
00159 
00160       setlst.addPut(addr, ROC_CMD_LST_PUT | (lst.oper(n).addr & ROC_CMD_LST_ADDRMASK));
00161       addr+=4;
00162       setlst.addPut(addr, lst.oper(n).value);
00163       addr+=4;
00164    }
00165 
00166    // check if last list command not specified, add it
00167 
00168    if ((lst.number()>0) && (lst.oper(lst.number()-1).addr != ROC_CMD_LST_ACTIVE)) {
00169 
00170       if (addr >= ROC_CMD_LST_MEM + ROC_CMD_LST_SIZE) {
00171          Debug(-1, "Commands list to long %d for slot %u", lst.number(), num);
00172          return ROC_VALUE_ERROR;
00173       }
00174 
00175       setlst.addPut(addr, ROC_CMD_LST_PUT | ROC_CMD_LST_ACTIVE);
00176       addr+=4;
00177       setlst.addPut(addr, 0);
00178       addr+=4;
00179    }
00180 
00181    return operGen(setlst, tmout);
00182 }
00183 
00184 //----------------------------------------------------------------------------
00186 
00190 int roc::Board::downloadCommandsList(unsigned num, base::OperList& lst, double tmout)
00191 {
00192    lst.clear();
00193 
00194    if (num >= ROC_CMD_LST_NUMBER) {
00195       Debug(-1, "Wrong number %u of commands list", num);
00196       return ROC_ADDRESS_ERROR;
00197    }
00198 
00199    base::OperList getlst;
00200 
00201    unsigned addr = ROC_CMD_LST_MEM + num * ROC_CMD_LST_SIZE / ROC_CMD_LST_NUMBER;
00202 
00203    unsigned lastaddr = addr + ROC_CMD_LST_SIZE / ROC_CMD_LST_NUMBER;
00204 
00205    while (addr<lastaddr) {
00206       getlst.addGet(addr);
00207       addr+=4;
00208    }
00209 
00210    int res = operGen(getlst, tmout);
00211 
00212    if (res!=0) return res;
00213 
00214    for (int n=0;n<getlst.number();n+=2) {
00215       uint32_t addr = getlst.oper(n).value;
00216       uint32_t value = getlst.oper(n+1).value;
00217 
00218       if ((addr & ROC_CMD_LST_PUT) == 0) {
00219          Debug(-1, "Commands list %u has non-Put operation", num);
00220          return ROC_VALUE_ERROR;
00221       }
00222 
00223       addr = addr & ROC_CMD_LST_ADDRMASK;
00224       if (addr==ROC_CMD_LST_ACTIVE) break;
00225       lst.addPut(addr, value);
00226    }
00227 
00228    return 0;
00229 }
00230 
00231 
00232 //----------------------------------------------------------------------------
00234 
00242 int roc::Board::uploadStartDaqCmdList(bool reset_frontend, bool reset_fifo)
00243 {
00244    base::OperList lst;
00245    uint32_t hw_kind = getRocFrontendKind();
00246 
00247    if (hw_kind==kind_nXYTER) {
00248 
00249       if (reset_frontend && (getTransportKind() == kind_UDP)) {
00250          lst.addPut(ROC_NX_TS_RESET, 1);
00251          lst.addPut(ROC_NX_TS_RESET, 0);
00252       }
00253       if (reset_fifo) {
00254          lst.addPut(ROC_NX_FIFO_RESET, 1);
00255          lst.addPut(ROC_NX_FIFO_RESET, 0);
00256       }
00257 
00258    } else 
00259 
00260       if ((hw_kind==kind_FEET) || (hw_kind==kind_oldFEET)) {
00261          if (reset_frontend)
00262             lst.addPut(ROC_FEET_RESET, 1);
00263          if (reset_fifo) {
00264             lst.addPut(ROC_FEET_FIFO_RESET, 1);
00265             lst.addPut(ROC_FEET_FIFO_RESET, 0);
00266          }
00267          lst.addPut(ROC_FEET_CMD_TO_FEET, 0x28);
00268          lst.addPut(ROC_FEET_CMD_TO_FEET, 0x2f);
00269       }
00270 
00271    if (getTransportKind() == kind_UDP)
00272       lst.addPut(ROC_ETH_START_DAQ, 1);
00273    else
00274       lst.addPut(ROC_OPTICS_START_DAQ, 1);
00275 
00276    return uploadCommandsList(0, lst, 3.);
00277 }
00278 
00279 //----------------------------------------------------------------------------
00281 
00285 int roc::Board::uploadStopDaqCmdList()
00286 {
00287    base::OperList lst;
00288 
00289    if (getTransportKind() == kind_UDP)
00290       lst.addPut(ROC_ETH_STOP_DAQ, 1);
00291    else
00292       lst.addPut(ROC_OPTICS_STOP_DAQ, 1);
00293 
00294    return uploadCommandsList(1, lst, 3.);
00295 }
00296 
00297 
00299 
00303 int roc::Board::setToDefault()
00304 {
00305    int res = base::Board::setToDefault();
00306    if (res==0) res = uploadStartDaqCmdList();
00307    if (res==0) res = uploadStopDaqCmdList();
00308    return res;
00309 }
00310 
00311 //----------------------------------------------------------------------------
00313 
00318 int roc::Board::invokeCommandsList(unsigned num, double tmout)
00319 {
00320    return put(ROC_CMD_LST_NR, num, tmout);
00321 }
00322 
00323 //----------------------------------------------------------------------------
00324 
00325 roc::Board* roc::Board::Connect(const char* name, roc::ClientRole role)
00326 {
00327    std::string sname(name);
00328 
00329    base::Board* brd = base::Board::Connect(sname.c_str(), (base::ClientRole) role);
00330 
00331    if (brd==0) return 0;
00332 
00333    roc::Board* rocbrd = dynamic_cast<roc::Board*> (brd);
00334 
00335    if (rocbrd==0) {
00336       fprintf(stderr,"Non-ROC board created with url %s\n", name);
00337       base::Board::Close(brd);
00338       return 0;
00339    }
00340 
00341    return rocbrd;
00342 }
00343 
00344 //----------------------------------------------------------------------------
00345 
00346 bool roc::Board::Close(Board* brd)
00347 {
00348    return base::Board::Close(brd);
00349 }
00350 
00351 //----------------------------------------------------------------------------
00353 
00354 uint32_t roc::Board::getRoclibVersion()
00355 {
00356    return KNUT_VERSION;
00357 }
00358 
00359 //----------------------------------------------------------------------------
00361 
00362 uint32_t roc::Board::getRocHardwareVersion()
00363 {
00364    uint32_t val = 0;
00365    get(ROC_HWV, val);
00366    return val;
00367 }
00368 
00369 //----------------------------------------------------------------------------
00371 
00381 uint32_t roc::Board::getRocHardwareType()
00382 {
00383    uint32_t val = 0;
00384    get(ROC_TYPE, val);
00385    return val;
00386 }
00387 
00388 //----------------------------------------------------------------------------
00390 
00391 void roc::Board::clearRocFifo()
00392 {
00393    operPP(ROC_NX_FIFO_RESET, 1,
00394           ROC_NX_FIFO_RESET, 0);
00395 }
00396 
00397 //----------------------------------------------------------------------------
00399 
00412 void roc::Board::restartRoc()
00413 {
00414    put(ROC_SYSTEM_RESET, 1);
00415 }
00416 
00417 //----------------------------------------------------------------------------
00419 
00429 int roc::Board::getRocThrottleState(uint32_t& val)
00430 {
00431    return get(ROC_NX_THROTTLE, val);
00432 }
00433 
00435 
00441 bool roc::Board::IsUdpAddress(const char* name)
00442 {
00443    base::Url url(name);
00444 
00445    // for any kind of invalid url we will try to create udp
00446    if (!url.IsValid()) return true;
00447 
00448    if (url.GetProtocol()=="udp") return true;
00449 
00450    if (url.GetProtocol().empty() && (url.GetHostName().find("abb")!=0)) return true;
00451 
00452    return false;
00453 
00454 }
00455 
00457 
00460 bool roc::Board::IsOpticAddress(const char* name)
00461 {
00462    base::Url url(name);
00463 
00464    if ((url.GetProtocol().length()>0) && (url.GetProtocol()!="optic")) return false;
00465 
00466    // any optic address must contain abb in the beginning of the address
00467    return url.GetHostName().find("abb")==0;
00468 }
00469 
00470 
00472 
00476 bool roc::Board::IsLmdFileAddress(const char* name)
00477 {
00478    base::Url url(name);
00479 
00480    if (!url.IsValid()) return false;
00481 
00482    if (url.GetProtocol()=="file") return true;
00483 
00484    if (url.GetProtocol().empty() && (url.GetFullName().find(".lmd")!=std::string::npos)) return true;
00485 
00486    return false;
00487 }

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