Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

RodModule.h

00001 //File: RodModule.h
00002 
00003 #ifndef SCTPIXELROD_RODMODULE_H 
00004 #define SCTPIXELROD_RODMODULE_H
00005 
00006 #include <fstream> 
00007 #include <iostream>
00008 #include <string>
00009 #include <ctime>     // Pick up clock() function and clock_t typedef
00010 #include <new>
00011 
00012 #include "BaseException.h"
00013 #include "RodPrimitive.h" 
00014 #include "RodPrimList.h"
00015 #include "VmeInterface.h" 
00016 #include "VmePort.h"
00017 #include "VmeModule.h"
00018 #include "processor.h"
00019 #include "RodRegisterBits.h"
00020 #include "smSendTxtBuff.h"
00021 #include "RodDspAddresses.h"
00022 #include "RodVmeAddresses.h"
00023 #include "RodOutList.h"
00024 #include "txtBuffer.h"
00025 
00026 namespace SctPixelRod {
00027 
00028 // Forward definition
00029 class BocCard;
00030 
00031 enum TextBuffState {TEXT_IDLE, TEXT_RQ_SET, TEXT_READOUT, TEXT_ERROR};
00032 enum PrimState {PRIM_IDLE, PRIM_LOADED, PRIM_EXECUTING, PRIM_WAITING, PRIM_PAUSED}; 
00033 enum TEXT_BUFFER_TYPE {TEXT_ERR, TEXT_INFO, TEXT_DIAG, TEXT_XFER, TEXT_UNDEF};
00034 enum HpidMode {DYNAMIC, AUTO, NO_AUTO};
00035 
00036 //------------------------------NoImageFile--------------------------------- 
00037 
00049 class NoImageFile : public BaseException {
00050 public:
00051   NoImageFile( std::string descriptor, std::string fileName);
00052   std::string getFileName() {return m_fileName;};
00053   virtual void what(std::ostream&);
00054 
00055 private:
00056   std::string m_fileName;
00057 };                                                                             
00058 
00059 //------------------------------HpiException--------------------------------- 
00060 
00071 class HpiException : public BaseException {
00072 public:
00073   HpiException( std::string descriptor, unsigned long calcAddr, unsigned long readAddr);
00074   unsigned long getCalcAddr() {return m_calcAddr;};
00075   unsigned long getReadAddr() {return m_readAddr;};
00076   virtual void what(std::ostream&);
00077 
00078 private:
00079   unsigned long m_calcAddr;    // The calculated (expected) address
00080   unsigned long m_readAddr;    // The address actually read
00081 };                                                                            
00082 
00083 //------------------------------RodException------------------------------ 
00084 
00095 class RodException : public BaseException {
00096 public:
00097   RodException( std::string descriptor);
00098   RodException( std::string descriptor, unsigned long data1);
00099   RodException( std::string descriptor, unsigned long data1, unsigned long data2);
00100   unsigned long getData1() {return m_data1;};
00101   unsigned long getData2() {return m_data2;};
00102   unsigned long getNumData() {return m_numData;};
00103   virtual void what(std::ostream&);
00104   
00105 private:
00106   unsigned long m_numData;  // Number of data values returned
00107   unsigned long m_data1;    // First data value returned
00108   unsigned long m_data2;    // Second data value returned
00109 };                                                                            
00110 
00111 //------------------------------------------------------------------------------              
00113 
00123 class RodModule : public VmeModule {
00124   RodModule(const RodModule& rhs);
00125   RodModule &operator=(const RodModule & rhs);
00126 
00127 public:
00128 
00129   // Constructors, destructor, and assignment
00130   RodModule( unsigned long baseAddr, unsigned long mapSize, VmeInterface & ourInterface, 
00131              long numSlaves) throw (RodException&, VmeException &);
00132   virtual ~RodModule();                                  // Destructor
00133   
00134   // Accessor functions
00135 
00136   unsigned long getBaseAddress() {return m_baseAddress; }
00137   long getSlot() const { return m_slot; }
00138   unsigned long getSerialNumber() {return m_serialNumber;};
00139   unsigned long getRevision() {return m_revision;};
00140   void setNumSlaves( long numSlaves) { m_numSlaves = numSlaves; }
00141   long getNumSlaves() const { return m_numSlaves; }
00142   void setFinBufferSize( long finBufferSize) { m_finBufferSize = finBufferSize;}
00143   long getFinBufferSize() const { return m_finBufferSize; }
00144   std::string getMasterImageName() {return m_masterImageName; }
00145   std::string getslaveIpramName(long slaveNum) {return m_slaveIpramName[slaveNum];}
00146   std::string getslaveIdramName(long slaveNum) {return m_slaveIdramName[slaveNum];}
00147   std::string getslaveExtName(long slaveNum) {return m_slaveExtName[slaveNum];}
00148   unsigned long getVmeCommandRegVal(long regNum) {
00149     return m_vmeCommandReg[regNum];
00150   };
00151   VmePort* getVmePort() {return m_myVmePort; };
00152   void setBoc(BocCard* myBoc);
00153   BocCard* getBocCard();
00154   void setOutList(RodOutList* outList) {m_myOutList = outList;};
00155   RodOutList* getOutList() {return m_myOutList;};
00156   PrimState getPrimState() {return m_myPrimState;};
00157   TextBuffState getTextState() {return m_myTextState;};
00158   
00159   long getMode() { return long(m_txtBuffer.mode);};
00160   long getOverwrite() {return long(m_txtBuffer.overwrite);};
00161   long getOverflow() {return long(m_txtBuffer.overflow);};
00162   long getWrap() {return long(m_txtBuffer.wrap);};
00163   TEXT_BUFFER_TYPE getTextBufferType() {return m_textType;};
00164     
00178   void initialize();
00179   void initialize(bool resetFlag) throw (RodException &, VmeException &);
00180   
00184   void reset() throw (RodException&, VmeException &);
00185 
00190   void status() throw();
00191 
00196   bool verify() throw();
00197   
00205   void initSlaveDsp(const std::string & ipramFile,
00206      const std::string & idramFile,const std::string & extFile, 
00207      const long slaveNumber, char opt='n') throw(RodException&, NoImageFile&, VmeException &);
00208      
00213   void loadSlaveImage(const std::string & filename, const unsigned long address,
00214         const long slaveNumber, char opt='n') 
00215         throw (NoImageFile &, RodException &, VmeException &);
00216                       
00220   void startSlave(const long slaveNumber, char mode='s') throw(RodException &, VmeException &);
00221   
00230   void synchSendPrim(RodPrimitive & prim) throw (RodException &, VmeException &) ;
00231 
00243   void sendPrimList(RodPrimList *l) throw(PrimListException &, VmeException &) ;
00244   
00249   PrimState primHandler() throw (RodException &, VmeException &);
00250   
00252   inline bool getDspAck() {return readRodStatusBit(0, DSPACK);};
00253   
00255   inline void setInListReady(){setVmeCommandRegBit(INLISTRDY); return;};
00256   
00258   void deleteOutList() throw() ;
00259 
00263   inline long getAllTextBuffBits() {   
00264     unsigned long regValue;
00265     regValue = readRodStatusReg(0);
00266     return (regValue>>TEXT_BUFF_NOT_EMPTY[0] & 0xF);
00267   };
00268   
00274   TextBuffState textHandler() throw(VmeException &) ;
00275   
00281   void getTextBuffer(char * buffer, long & length, TEXT_BUFFER_TYPE & type)
00282       throw();
00283   
00286   void clearTextBuffer() throw();
00287 
00289   inline unsigned long readRodStatusReg(long regNumber) {
00290     unsigned long regValue;
00291     regValue = mdspSingleRead(STATUS_REG[regNumber]);
00292     return regValue;
00293   };
00294   
00296   inline unsigned long readRodCommandReg(long regNumber) {
00297     unsigned long regValue;
00298     regValue = mdspSingleRead(COMMAND_REG[regNumber]);
00299     return regValue;
00300   };
00301   
00303   inline bool readRodStatusBit(long regNumber, long bitNumber) {
00304     unsigned long rodStatusReg;
00305     rodStatusReg = readRodStatusReg(regNumber);
00306     return (0x1) & (readRodStatusReg(regNumber)>>bitNumber);
00307   };
00308   
00310   inline void setVmeCommandRegBit(const long bitNumber) {
00311     setBit(&m_vmeCommandReg[0], bitNumber);
00312     mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00313     return;
00314   };
00315   
00317   inline void clearVmeCommandRegBit(const long bitNumber) {
00318     clearBit(&m_vmeCommandReg[0], bitNumber);
00319     mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00320     return;
00321   };
00322   
00327   void hpiLoad(const unsigned long hpiReg, const unsigned long hpiValue) 
00328        throw(VmeException &);
00329 
00334   unsigned long hpiFetch(const unsigned long hpiReg) throw(VmeException &);
00335 
00339   unsigned long mdspSingleRead(const unsigned long dspAddr) throw(VmeException &);
00340 
00344   void mdspSingleWrite(unsigned long dspAddr, unsigned long buffer) 
00345     throw(VmeException &);
00346 
00352   void mdspBlockRead(const unsigned long dspAddr, unsigned long *buffer, 
00353        long wordCount, HpidMode mode=DYNAMIC) 
00354        throw (HpiException &, VmeException &);
00355 
00361   void mdspBlockWrite(const unsigned long dspAddr, unsigned long *buffer, 
00362        long wordCount, HpidMode mode=DYNAMIC) 
00363        throw (HpiException &, VmeException &);
00364 
00368   void mdspBlockDump(const unsigned long firstAddress, 
00369        const unsigned long lastAddress, const std::string & fileName) 
00370        throw(RodException &, VmeException &);
00371                      
00375   void slvHpiLoad(unsigned long hpiReg, unsigned long hpiValue,
00376                            long slaveNum) throw(VmeException &);
00377                            
00381   unsigned long slvHpiFetch(unsigned long hpiReg, long slaveNum) 
00382                 throw(VmeException &);
00383 
00387   unsigned long slvSingleRead(unsigned long dspAddr, long slaveNum ) 
00388                 throw(VmeException &);
00389                                           
00394   void slvSingleWrite(unsigned long dspAddr, unsigned long buffer, 
00395        long slaveNum) throw(VmeException &);
00396 
00402   void slvBlockRead(const unsigned long dspAddr, unsigned long buffer[],
00403        const long wordCount, long slaveNum, HpidMode mode=DYNAMIC) 
00404        throw (HpiException &, VmeException &);
00405                 
00411   void slvBlockWrite(unsigned long dspAddr, unsigned long buffer[], 
00412        const long wordCount, long slaveNum, HpidMode mode=DYNAMIC) 
00413         throw (HpiException &, VmeException &);
00414          
00417   void resetMasterDsp() throw(RodException &, VmeException &);
00418   
00421   void resetSlaveDsp(long slaveNumber) throw(RodException &, VmeException &);
00422   
00425   void resetAllDsps() throw(RodException &, VmeException &);
00426   
00429   void chipEraseHpi() throw(VmeException &);
00430   
00433   void sectorErase(unsigned long sectorBaseAddress) 
00434        throw(RodException &, VmeException &) ;
00435   
00438   void writeByteToFlash(unsigned long address, UINT8 data) 
00439        throw (RodException &, VmeException &);
00440   
00443   void writeBlockToFlash(unsigned long address, UINT8 *data, 
00444                       unsigned long numBytes) throw(RodException &, VmeException &);
00445                       
00448   void writeBlockToFlashHpi(unsigned long address, UINT8 *data, unsigned long numBytes)
00449                             throw (RodException &, VmeException &);
00450                             
00453   UINT8 readByteFromFlash(unsigned long address, long updateAddress) 
00454                             throw (RodException &, VmeException &);
00455                             
00458   void vmeWriteElementFlash(UINT8 value, unsigned long address, 
00459                  long handshakeBit) throw (RodException &, VmeException &);
00460                  
00463   void readBlockFromFlash(unsigned long address, UINT8 *buffer, unsigned long
00464                           numBytes) throw(RodException &, VmeException &) ;
00465                           
00468   void commonEraseCommands(unsigned long flashBaseAddr) throw(RodException &, VmeException &);
00469   
00473   void commonEraseCommandsHpi(unsigned long flashBaseAddr) throw(VmeException &);
00474    
00478   unsigned long getFlashSectorSize();
00479   
00482   void sleep(const double milliSecs);
00483 
00486   unsigned long checkSum(const unsigned long *sourceArray, const long wordCount);
00487   
00490   unsigned long endianReverse32(const unsigned long inVal);
00491   
00492 
00493 private:
00495   inline void setBit(unsigned long *var, long bitNumber) {
00496     *var = *var | (1<<bitNumber);
00497     return;
00498   }
00499   
00500   inline void clearBit(unsigned long *var, long bitNumber) {
00501     *var&=(~(1<<bitNumber));
00502     return;
00503   }
00504   
00505   inline bool readBit(unsigned long var, long bitNumber) 
00506     {return ((var>>bitNumber)&1);}
00507   
00509   long m_slot;
00510   
00512   unsigned long m_serialNumber;
00513   
00515   unsigned long m_revision;
00516   
00518   VmePort* m_myVmePort;
00519 
00521   long m_numSlaves;
00522 
00524   long m_finBufferSize;
00525 
00527   std::string m_masterImageName;
00528 
00530   std::string m_slaveIpramName[4];
00531 
00533   std::string m_slaveIdramName[4];
00534 
00536   std::string m_slaveExtName[4];
00537 
00539   unsigned long m_vmeCommandReg[2];
00540   unsigned long m_rodStatusReg[3];
00541   
00543   RodOutList* m_myOutList;
00544   
00546   PrimState m_myPrimState;
00547       
00549   TextBuffState m_myTextState;
00550   
00552   TEXT_BUFFER_TYPE m_textType;
00553   
00555   struct TXTBUFFER m_txtBuffer;
00556   
00558   char m_textData[TEXT_BUFF_SIZE];
00559   
00561   unsigned long* m_textBuff[N_TXT_BUFFS];
00562   
00564   BocCard* m_myBoc;
00565   
00566 }; // End of class RodModule declaration
00567 
00568 }; //  End namespace SctPixelRod
00569 
00570 //---------------------------- Overload operator<< -----------------------------
00571 /* This overloaded operator lets us use cout to print the status of the ROD
00572  * and exception information.
00573 */
00574   std::ostream& operator<<(std::ostream& os, SctPixelRod::RodModule& rod);
00575 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::RodException& rodExcept); */
00576 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::HpiException& hpiExcept); */
00577 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::NoImageFile& noImageExcept); */
00578 
00579 #endif // SCTPIXELROD_RODMODULE_H
00580 

Generated on Thu Jul 15 09:50:51 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5