Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | 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 //dpsf: #include "smSendTxtBuff.h"
00021 #include "comRegDfns.h" //dpsf: added
00022 #include "txtBuffer.h"  //dpsf: added
00023 #include "memoryPartitions.h" //dpsf: added temp. see comments in memoryPartitions.h
00024 #include "RodDspAddresses.h"
00025 #include "RodVmeAddresses.h"
00026 #include "RodOutList.h"
00027 #include "txtBuffer.h"
00028 
00029 namespace SctPixelRod {
00030 
00031 // Forward definition
00032 class BocCard;
00033 
00034 enum TextBuffState {TEXT_IDLE, TEXT_RQ_SET, TEXT_READOUT, TEXT_ERROR};
00035 enum PrimState {PRIM_IDLE, PRIM_LOADED, PRIM_EXECUTING, PRIM_WAITING, PRIM_PAUSED}; 
00036 enum TEXT_BUFFER_TYPE {TEXT_ERR, TEXT_INFO, TEXT_DIAG, TEXT_XFER, TEXT_UNDEF};
00037 enum HpidMode {DYNAMIC, AUTO, NO_AUTO};
00038 
00039 //------------------------------NoImageFile--------------------------------- 
00040 
00052 class NoImageFile : public BaseException {
00053 public:
00054   NoImageFile( std::string descriptor, std::string fileName);
00055   std::string getFileName() {return m_fileName;};
00056   virtual void what(std::ostream&);
00057 
00058 private:
00059   std::string m_fileName;
00060 };                                                                             
00061 
00062 //------------------------------HpiException--------------------------------- 
00063 
00074 class HpiException : public BaseException {
00075 public:
00076   HpiException( std::string descriptor, unsigned long calcAddr, unsigned long readAddr);
00077   unsigned long getCalcAddr() {return m_calcAddr;};
00078   unsigned long getReadAddr() {return m_readAddr;};
00079   virtual void what(std::ostream&);
00080 
00081 private:
00082   unsigned long m_calcAddr;    // The calculated (expected) address
00083   unsigned long m_readAddr;    // The address actually read
00084 };                                                                            
00085 
00086 //------------------------------RodException------------------------------ 
00087 
00098 class RodException : public BaseException {
00099 public:
00100   RodException( std::string descriptor);
00101   RodException( std::string descriptor, unsigned long data1);
00102   RodException( std::string descriptor, unsigned long data1, unsigned long data2);
00103   unsigned long getData1() {return m_data1;};
00104   unsigned long getData2() {return m_data2;};
00105   unsigned long getNumData() {return m_numData;};
00106   virtual void what(std::ostream&);
00107   
00108 private:
00109   unsigned long m_numData;  // Number of data values returned
00110   unsigned long m_data1;    // First data value returned
00111   unsigned long m_data2;    // Second data value returned
00112 };                                                                            
00113 
00114 //------------------------------------------------------------------------------              
00116 
00126 class RodModule : public VmeModule {
00127   RodModule(const RodModule& rhs);
00128   RodModule &operator=(const RodModule & rhs);
00129 
00130 public:
00131 
00132   // Constructors, destructor, and assignment
00133   RodModule( unsigned long baseAddr, unsigned long mapSize, VmeInterface & ourInterface, 
00134              long numSlaves) throw (RodException&, VmeException &);
00135   virtual ~RodModule();                                  // Destructor
00136   
00137   // Accessor functions
00138 
00139   unsigned long getBaseAddress() {return m_baseAddress; }
00140   long getSlot() const { return m_slot; }
00141   unsigned long getSerialNumber() {return m_serialNumber;};
00142   unsigned long getRevision() {return m_revision;};
00143   void setNumSlaves( long numSlaves) { m_numSlaves = numSlaves; }
00144   long getNumSlaves() const { return m_numSlaves; }
00145   void setFinBufferSize( long finBufferSize) { m_finBufferSize = finBufferSize;}
00146   long getFinBufferSize() const { return m_finBufferSize; }
00147   std::string getMasterImageName() {return m_masterImageName; }
00148   std::string getslaveIpramName(long slaveNum) {return m_slaveIpramName[slaveNum];}
00149   std::string getslaveIdramName(long slaveNum) {return m_slaveIdramName[slaveNum];}
00150   std::string getslaveExtName(long slaveNum) {return m_slaveExtName[slaveNum];}
00151   unsigned long getVmeCommandRegVal(long regNum) {
00152     return m_vmeCommandReg[regNum];
00153   };
00154   VmePort* getVmePort() {return m_myVmePort; };
00155   void setBoc(BocCard* myBoc);
00156   BocCard* getBocCard();
00157   void setOutList(RodOutList* outList) {m_myOutList = outList;};
00158   RodOutList* getOutList() {return m_myOutList;};
00159   PrimState getPrimState() {return m_myPrimState;};
00160   TextBuffState getTextState() {return m_myTextState;};
00161   
00162   long getMode() { return long(m_txtBuffer.mode);};
00163   long getOverwrite() {return long(m_txtBuffer.overwrite);};
00164   long getOverflow() {return long(m_txtBuffer.overflow);};
00165   long getWrap() {return long(m_txtBuffer.wrap);};
00166   TEXT_BUFFER_TYPE getTextBufferType() {return m_textType;};
00167     
00181   void initialize();
00182   void initialize(bool resetFlag) throw (RodException &, VmeException &);
00183   
00187   void reset() throw (RodException&, VmeException &);
00188 
00194   void status() throw();
00195   void status(std::ostream& oss) throw();
00196 
00201   bool verify() throw();
00202   
00210   void initSlaveDsp(const std::string & ipramFile,
00211      const std::string & idramFile,const std::string & extFile, 
00212      const long slaveNumber, char opt='n') throw(RodException&, NoImageFile&, VmeException &);
00213      
00218   void loadSlaveImage(const std::string & filename, const unsigned long address,
00219         const long slaveNumber, char opt='n') 
00220         throw (NoImageFile &, RodException &, VmeException &);
00221                       
00225   void startSlave(const long slaveNumber, char mode='s') throw(RodException &, VmeException &);
00226   
00235   void synchSendPrim(RodPrimitive & prim) throw (RodException &, VmeException &) ;
00236 
00248   void sendPrimList(RodPrimList *l) throw(PrimListException &, VmeException &) ;
00249   
00254   PrimState primHandler() throw (RodException &, VmeException &);
00255   
00257   inline bool getDspAck() {return readRodStatusBit(0, DSPACK);};
00258   
00260   inline void setInListReady(){setVmeCommandRegBit(INLISTRDY); return;};
00261   
00263   void deleteOutList() throw() ;
00264 
00268   inline long getAllTextBuffBits() {   
00269     unsigned long regValue;
00270     regValue = readRodStatusReg(0);
00271     return (regValue>>TEXT_BUFF_NOT_EMPTY[0] & 0xF);
00272   };
00273   
00279   TextBuffState textHandler() throw(VmeException &) ;
00280   
00286   void getTextBuffer(char * buffer, long & length, TEXT_BUFFER_TYPE & type)
00287       throw();
00288   
00291   void clearTextBuffer() throw();
00292 
00294   inline unsigned long readRodStatusReg(long regNumber) {
00295     unsigned long regValue;
00296     regValue = mdspSingleRead(STATUS_REG[regNumber]);
00297     return regValue;
00298   };
00299   
00301   inline unsigned long readRodCommandReg(long regNumber) {
00302     unsigned long regValue;
00303     regValue = mdspSingleRead(COMMAND_REG[regNumber]);
00304     return regValue;
00305   };
00306   
00308   inline bool readRodStatusBit(long regNumber, long bitNumber) {
00309     unsigned long rodStatusReg;
00310     rodStatusReg = readRodStatusReg(regNumber);
00311     return (0x1) & (readRodStatusReg(regNumber)>>bitNumber);
00312   };
00313   
00315   inline void setVmeCommandRegBit(const long bitNumber) {
00316     setBit(&m_vmeCommandReg[0], bitNumber);
00317     mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00318     return;
00319   };
00320   
00322   inline void clearVmeCommandRegBit(const long bitNumber) {
00323     clearBit(&m_vmeCommandReg[0], bitNumber);
00324     mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00325     return;
00326   };
00327   
00332   void hpiLoad(const unsigned long hpiReg, const unsigned long hpiValue) 
00333        throw(VmeException &);
00334 
00339   unsigned long hpiFetch(const unsigned long hpiReg) throw(VmeException &);
00340 
00344   unsigned long mdspSingleRead(const unsigned long dspAddr) throw(VmeException &);
00345 
00349   void mdspSingleWrite(unsigned long dspAddr, unsigned long buffer) 
00350     throw(VmeException &);
00351 
00357   void mdspBlockRead(const unsigned long dspAddr, unsigned long *buffer, 
00358        long wordCount, HpidMode mode=DYNAMIC) 
00359        throw (HpiException &, VmeException &);
00360 
00366   void mdspBlockWrite(const unsigned long dspAddr, unsigned long *buffer, 
00367        long wordCount, HpidMode mode=DYNAMIC) 
00368        throw (HpiException &, VmeException &);
00369 
00373   void mdspBlockDump(const unsigned long firstAddress, 
00374        const unsigned long lastAddress, const std::string & fileName) 
00375        throw(RodException &, VmeException &);
00376                      
00380   void slvHpiLoad(unsigned long hpiReg, unsigned long hpiValue,
00381                            long slaveNum) throw(VmeException &);
00382                            
00386   unsigned long slvHpiFetch(unsigned long hpiReg, long slaveNum) 
00387                 throw(VmeException &);
00388 
00392   unsigned long slvSingleRead(unsigned long dspAddr, long slaveNum ) 
00393                 throw(VmeException &);
00394                                           
00399   void slvSingleWrite(unsigned long dspAddr, unsigned long buffer, 
00400        long slaveNum) throw(VmeException &);
00401 
00407   void slvBlockRead(const unsigned long dspAddr, unsigned long buffer[],
00408        const long wordCount, long slaveNum, HpidMode mode=DYNAMIC) 
00409        throw (HpiException &, VmeException &);
00410                 
00416   void slvBlockWrite(unsigned long dspAddr, unsigned long buffer[], 
00417        const long wordCount, long slaveNum, HpidMode mode=DYNAMIC) 
00418         throw (HpiException &, VmeException &);
00419          
00422   void resetMasterDsp() throw(RodException &, VmeException &);
00423   
00426   void resetSlaveDsp(long slaveNumber) throw(RodException &, VmeException &);
00427   
00430   void resetAllDsps() throw(RodException &, VmeException &);
00431   
00434   void chipEraseHpi() throw(VmeException &);
00435   
00438   void sectorErase(unsigned long sectorBaseAddress) 
00439        throw(RodException &, VmeException &) ;
00440   
00443   void writeByteToFlash(unsigned long address, UINT8 data) 
00444        throw (RodException &, VmeException &);
00445   
00448   void writeBlockToFlash(unsigned long address, UINT8 *data, 
00449                       unsigned long numBytes) throw(RodException &, VmeException &);
00450                       
00453   void writeBlockToFlashHpi(unsigned long address, UINT8 *data, unsigned long numBytes)
00454                             throw (RodException &, VmeException &);
00455                             
00458   UINT8 readByteFromFlash(unsigned long address, long updateAddress) 
00459                             throw (RodException &, VmeException &);
00460                             
00463   void vmeWriteElementFlash(UINT8 value, unsigned long address, 
00464                  long handshakeBit) throw (RodException &, VmeException &);
00465                  
00468   void readBlockFromFlash(unsigned long address, UINT8 *buffer, unsigned long
00469                           numBytes) throw(RodException &, VmeException &) ;
00470                           
00473   void commonEraseCommands(unsigned long flashBaseAddr) throw(RodException &, VmeException &);
00474   
00478   void commonEraseCommandsHpi(unsigned long flashBaseAddr) throw(VmeException &);
00479    
00483   unsigned long getFlashSectorSize();
00484   
00487   void sleep(const double milliSecs);
00488 
00491   unsigned long checkSum(const unsigned long *sourceArray, const long wordCount);
00492   
00495   unsigned long endianReverse32(const unsigned long inVal);
00496   
00497 
00498 private:
00500   inline void setBit(unsigned long *var, long bitNumber) {
00501     *var = *var | (1<<bitNumber);
00502     return;
00503   }
00504   
00505   inline void clearBit(unsigned long *var, long bitNumber) {
00506     *var&=(~(1<<bitNumber));
00507     return;
00508   }
00509   
00510   inline bool readBit(unsigned long var, long bitNumber) 
00511     {return ((var>>bitNumber)&1);}
00512   
00514   long m_slot;
00515   
00517   unsigned long m_serialNumber;
00518   
00520   unsigned long m_revision;
00521   
00523   VmePort* m_myVmePort;
00524 
00526   long m_numSlaves;
00527 
00529   long m_finBufferSize;
00530 
00532   std::string m_masterImageName;
00533 
00535   std::string m_slaveIpramName[4];
00536 
00538   std::string m_slaveIdramName[4];
00539 
00541   std::string m_slaveExtName[4];
00542 
00544   unsigned long m_vmeCommandReg[2];
00545   unsigned long m_rodStatusReg[3];
00546   
00548   RodOutList* m_myOutList;
00549   
00551   PrimState m_myPrimState;
00552       
00554   TextBuffState m_myTextState;
00555   
00557   TEXT_BUFFER_TYPE m_textType;
00558   
00560   struct TXTBUFFER m_txtBuffer;
00561   
00563   char m_textData[TEXT_BUFF_SIZE];
00564   
00566   unsigned long* m_textBuff[N_TXT_BUFFS];
00567   
00569   BocCard* m_myBoc;
00570   
00571 }; // End of class RodModule declaration
00572 
00573 }; //  End namespace SctPixelRod
00574 
00575 //---------------------------- Overload operator<< -----------------------------
00576 /* This overloaded operator lets us use cout to print the status of the ROD
00577  * and exception information.
00578 */
00579   std::ostream& operator<<(std::ostream& os, SctPixelRod::RodModule& rod);
00580 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::RodException& rodExcept); */
00581 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::HpiException& hpiExcept); */
00582 /*   std::ostream& operator<<(std::ostream& os, SctPixelRod::NoImageFile& noImageExcept); */
00583 
00584 #endif // SCTPIXELROD_RODMODULE_H
00585 

Generated on Fri Dec 16 19:38:16 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5