// File: RodStatus.cxx // $Header: /afs/cern.ch/user/s/sctpixel/private/cvsroot//RodDaq/RodCrate/RodStatus.cxx,v 1.5 2004/06/15 15:47:23 tegen Exp $ //! Namespace for the common routines for SCT and PIXEL ROD software. #include "RodStatus.h" #include namespace SctPixelRod { //------------------------------RodStatus--------------------------------- // This class collects the status of a given ROD // // Authors Tom Meyer (meyer@iastate.edu) - originator, // Fredrik Tegenfeldt (fredrik.tegenfeldt@cern.ch) RodStatus::RodStatus() { clear(); } RodStatus::RodStatus( RodModule & rod ) { try { snapShot(rod); } catch (...) { throw; } } RodStatus::RodStatus( const RodStatus & other ) { copy(other); } RodStatus::~RodStatus() { } RodStatus & RodStatus::operator=(const RodStatus & other) { copy(other); return *this; } void RodStatus::copy(const RodStatus & other) { m_rod = other.getRod(); m_sane = other.isSane(); m_revision = other.getRevision(); m_mdspMapRev = other.getMdspMapRev(); m_mdspProgRev = other.getMdspProgRev(); m_fpgaFmtRev = other.getFpgaFmtRev(); m_fpgaEfbRev = other.getFpgaEfbRev(); m_fpgaRtrRev = other.getFpgaRtrRev(); m_fpgaRcfRev = other.getFpgaRcfRev(); m_serialNumber = other.getSerialNumber(); m_slotNumber = other.getSlotNumber(); m_numSlaves = other.getNumSlaves(); m_statusReg[0] = other.getStatusReg(0); m_statusReg[1] = other.getStatusReg(1); m_statusReg[2] = other.getStatusReg(2); m_commandReg[0] = other.getCommandReg(0); m_commandReg[1] = other.getCommandReg(1); m_primState = other.getPrimState(); m_textState = other.getTextState(); } void RodStatus::clear() { m_rod = 0; m_sane = false; m_serialNumber = 0; m_revision = 0; m_mdspMapRev = 0; m_mdspProgRev = 0; m_fpgaFmtRev = 0; m_fpgaEfbRev = 0; m_fpgaRtrRev = 0; m_fpgaRcfRev = 0; m_slotNumber = 0; m_numSlaves = 0; // m_statusReg[0] = 0; m_statusReg[1] = 0; m_statusReg[2] = 0; m_commandReg[0] = 0; m_commandReg[1] = 0; // m_primState = PRIM_IDLE; m_textState = TEXT_IDLE; } inline const char *RodStatus::getPrimStateTxt() const { return getPrimStateTxt(m_primState); } const char *RodStatus::getPrimStateTxt(PrimState st) const { static const char *str[] = {"Idle","Loaded","Executing","Waiting","Paused","Unknown"}; const char *rval; switch (st) { case PRIM_IDLE: rval = str[0]; break; case PRIM_LOADED: rval = str[1]; break; case PRIM_EXECUTING: rval = str[2]; break; case PRIM_WAITING: rval = str[3]; break; case PRIM_PAUSED: rval = str[4]; break; default: rval = str[5]; break; } return rval; } inline const char *RodStatus::getTextStateTxt() const { return getTextStateTxt(m_textState); } const char *RodStatus::getTextStateTxt(TextBuffState st) const { static const char *str[] = {"Idle","RQ set","Readout","Error","Unknown"}; const char *rval; switch (st) { case TEXT_IDLE: rval = str[0]; break; case TEXT_RQ_SET: rval = str[1]; break; case TEXT_READOUT: rval = str[2]; break; case TEXT_ERROR: rval = str[3]; break; default: rval = str[4]; //unknown break; } return rval; } void RodStatus::snapShot(RodModule &rod) { try { m_sane = false; m_rod = &rod; VmePort* vmePort = rod.getVmePort(); unsigned long fpgaStatus6 = vmePort->read32(FPGA_STATUS_REG_REL_ADDR[6]); unsigned long maskedCor = fpgaStatus6 & 0xff000000; // correct byte order unsigned long maskedRev = fpgaStatus6 & 0x000000ff; // wrong byte order m_sane = ((maskedCor == 0xad000000) || (maskedRev == 0x000000ad)); m_correctByteOrder = (maskedCor == 0xad000000); m_slotNumber = rod.getSlot(); m_revision = rod.getRevision(); MdspMemoryMap *mdspMap = rod.getMdspMap(); if (mdspMap) { m_mdspMapRev = mdspMap->revision(); m_mdspProgRev = mdspMap->dspVersion(); m_fpgaFmtRev = mdspMap->fmtVersion(); m_fpgaEfbRev = mdspMap->efbVersion(); m_fpgaRtrRev = mdspMap->rtrVersion(); m_fpgaRcfRev = mdspMap->rcfVersion(); } else { m_mdspMapRev = 0; m_mdspProgRev = 0; m_fpgaFmtRev = 0; m_fpgaEfbRev = 0; m_fpgaRtrRev = 0; m_fpgaRcfRev = 0; } // m_serialNumber = rod.getSerialNumber(); m_numSlaves = rod.getNumSlaves(); for (long i=0; i<3; i++) { m_statusReg[i] = rod.readRodStatusReg(i); } for (long i=0; i<2; i++) { m_commandReg[i] = rod.readRodCommandReg(i); } m_primState = rod.getPrimState(); m_textState = rod.getTextState(); } catch (...) { // std::cout << "Some exception occured in snapShot!" << std::endl; throw; } return; } void RodStatus::writeToXml(std::ofstream& os) const { if (!m_rod) {return;} // should throw an exception if (!os.is_open()) {return;} // idem os << "" << std::endl; os << "" << std::endl; os << "" << std::endl; os << " " << m_slotNumber << " " << std::endl; os << " " << (m_correctByteOrder ? 1:-1) << " " << std::endl; os << " " << m_serialNumber << " " << std::endl; os << " " << m_revision << " " << std::endl; os << " " << m_mdspMapRev << " " << std::endl; os << " " << m_mdspProgRev << " " << std::endl; os << " " << m_fpgaFmtRev << " " << std::endl; os << " " << m_fpgaEfbRev << " " << std::endl; os << " " << m_fpgaRtrRev << " " << std::endl; os << " " << m_fpgaRcfRev << " " << std::endl; os << " " << m_numSlaves << " " << std::endl; os << " " << m_statusReg[0] << " " << std::endl; os << " " << m_statusReg[1] << " " << std::endl; os << " " << m_statusReg[2] << " " << std::endl; os << " " << m_commandReg[0] << " " << std::endl; os << " " << m_commandReg[1] << " " << std::endl; os << " " << m_primState << " " << std::endl; os << " " << m_textState << " " << std::endl; os << "" << std::endl; } void RodStatus::writeToXml(std::string& fileName) const { std::ofstream fout; fout.open(fileName.c_str(),std::ios::out); writeToXml(fout); } // overloaded << operator std::ostream& operator<<(std::ostream& os, RodStatus& status) { std::_Ios_Fmtflags oldOsFlags = os.flags(); os << std::endl; os << "================== R O D S T A T U S ====================" << std::endl; os << " Slot : " << status.getSlotNumber() << std::endl; os << " Base adress : " << std::hex << std::setfill('0') << "0x" << std::setw(8) << (status.getSlotNumber()<<24) << std::endl; os << " Byte order OK : " << (status.isByteOrderOK() ? "Yes":"No") << std::endl; os << " Serial Number : " << std::dec << status.getSerialNumber() << std::endl; os << " ROD rev. : " << std::hex << status.getRevision() << std::endl; os << " MDSP memory map rev. : " << std::dec << status.getMdspMapRev() << std::endl; os << " MDSP program rev. : " << std::hex << status.getMdspProgRev() << std::endl; os << " FMT program rev. : " << std::hex << status.getFpgaFmtRev() << std::endl; os << " EFB program rev. : " << std::hex << status.getFpgaEfbRev() << std::endl; os << " RTR program rev. : " << std::hex << status.getFpgaRtrRev() << std::endl; os << " RCF program rev. : " << std::hex << status.getFpgaRcfRev() << std::endl; os << " Number of slave DSPs : " << status.getNumSlaves() << std::endl; os << std::endl; os << " Status registers[0-2] : " << std::hex << std::setfill('0') << "0x" << std::setw(8) << status.getStatusReg(0) << " " << "0x" << std::setw(8) << status.getStatusReg(1) << " " << "0x" << std::setw(8) << status.getStatusReg(2) << std::endl; os << " Command registers[0-1]: " << std::hex << std::setfill('0') << "0x" << std::setw(8) << status.getCommandReg(0) << " " << "0x" << std::setw(8) << status.getCommandReg(1) << std::endl; dec(os); os << " Primitive state : " << status.getPrimStateTxt() << std::endl; os << " Text State : " << status.getTextStateTxt() << std::endl; os << "==========================================================" << std::endl; os << std::endl; os.flags(oldOsFlags); // reset stream flags return os; } } // End namespace SctPixelRod