CCAENV1x90.h

Go to the documentation of this file.
00001 /*
00002     This software is Copyright by the Board of Trustees of Michigan
00003     State University (c) Copyright 2005.
00004 
00005     You may use this software under the terms of the GNU public license
00006     (GPL).  The terms of this license are described at:
00007 
00008      http://www.gnu.org/licenses/gpl.txt
00009 
00010      Author:
00011              Ron Fox
00012              NSCL
00013              Michigan State University
00014              East Lansing, MI 48824-1321
00015 */
00016 
00017 
00064 #ifndef __CCAENV1x90_H
00065 #define __CCAENV1x90_h
00066 
00067 
00068 #ifndef __STL_VECTOR
00069 #include <vector>
00070 #ifndef __STL_VECTOR
00071 #define __STL_VECTOR
00072 #endif
00073 #endif
00074 
00075 
00076 
00077 #ifndef __DESIGNBYCONTRACT_H
00078 #include "DesignByContract.h"
00079 #ifndef __DESIGNBYCONTRACT_H
00080 #define __DESIGNBYCONTRACT_H
00081 #endif
00082 #endif
00083 
00084 #ifndef VMEMODULE_H
00085 #include <VmeModule.h>
00086 #endif
00087 
00088 
00089 // Class definitions.
00090 
00091 
00092 class CCAENV1x90 
00093 {
00094   // Exported data types:
00095 
00096 public:
00101   typedef enum _ECLOutputSelect {
00102     DATA_READY,
00103     FULL,
00104     ALMOST_FULL,
00105     ERROR
00106   } ECLOutputSelect;
00107 
00108   struct TriggerConfiguration {
00109     unsigned short s_MatchWidth;
00110              short s_MatchOffset;
00111     unsigned short s_MatchExtra;
00112     unsigned short s_RejectMargin;
00113     unsigned short s_Subtracting;
00114   };
00115   typedef enum _EdgeMode {
00116     EdgeMode_Pair       = 0 ,
00117     EdgeMode_Leading    = 2,
00118     EdgeMode_Trailing   = 1,
00119     EdgeMode_Both       = 3
00120 
00121   } EdgeMode;
00122   typedef enum _Resolution {
00123     Res_25ps    = 3,                    // 1290 only.
00124     Res_100ps   = 2,
00125     Res_200ps   = 1,
00126     Res_800ps   = 0
00127   } Resolution;
00128   typedef enum _LEResolution {
00129     LE_100ps        = 0,
00130     LE_200ps       = 1,
00131     LE_400ps       = 2,
00132     LE_800ps       = 3,
00133     LE_1600ps      = 4,
00134     LE_3120ps      = 5,
00135     LE_6250ps      = 6,
00136     LE_12500ps     = 7
00137   } LEResolution;
00138   typedef enum _PWResolution {
00139     PW_100ps       = 0,
00140     PW_200ps       = 1,  
00141     PW_400ps       = 2,
00142     PW_800ps       = 3,
00143     PW_1600ps      = 4,
00144     PW_3200ps      = 5,
00145     PW_6250ps      = 6,
00146     PW_12500ps     = 7,
00147     PW_25ns        = 8,
00148     PW_50ns        = 9,
00149     PW_100ns       = 10,
00150     PW_200ns       = 11,
00151     PW_400ns       = 12,
00152     PW_800ns       = 13
00153   } PWResolution;
00154 
00155   typedef enum _DeadTime {
00156     DT_5ns       = 0,
00157     DT_10ns      = 1,
00158     DT_30ns      = 2,
00159     DT_100ns     = 3
00160   } DeadTime;
00161   // Instance data.
00162   typedef enum _HitMax {
00163     HITS_0       = 0,                   // No hits.
00164     HITS_1       = 1,
00165     HITS_2       = 2,
00166     HITS_4       = 3,
00167     HITS_8       = 4,
00168     HITS_16      = 5,
00169     HITS_32      = 6,
00170     HITS_64      = 7,
00171     HITS_128     = 8,
00172     HITS_UNLIMITED = 9          // No limit on hits.
00173   } HitMax;
00174   typedef enum _L1Size {
00175     L1_2wds,
00176     L1_4wds,
00177     L1_8wds,
00178     L1_16wds,
00179     L1_32wds,
00180     L1_64wds,
00181     L1_128wds,
00182     L1_256wds
00183   } L1Size;
00184 
00185   // public data
00186 
00187 public:
00188   // Error masks for Get/Set ErrorEnables:
00189   
00190   static const unsigned short ERR_VERNIER;
00191   static const unsigned short ERR_COARSE;
00192   static const unsigned short ERR_SELECT;
00193   static const unsigned short ERR_L1PARITY;
00194   static const unsigned short ERR_TFIFOPARITY;
00195   static const unsigned short ERR_MATCHERROR;
00196   static const unsigned short ERR_RFIFOPARITY;
00197   static const unsigned short ERR_RDOSTATE;
00198   static const unsigned short ERR_SUPPARITY;
00199   static const unsigned short ERR_CTLPARITY;
00200   static const unsigned short ERR_JTAGPARITY;
00201 
00202   // Tap masks for calibrate delayline.
00203   
00204   static const unsigned short TAP_CONTACT1;
00205   static const unsigned short TAP_CONTACT2;
00206   static const unsigned short TAP_CONTACT3;
00207 
00208   
00209 private:
00210   unsigned long m_nBase;        
00211   unsigned int  m_nCrate;       
00212   unsigned int  m_nSlot;        
00213   CVmeModule
00214             m_pRegisters;       
00215   unsigned int  m_nModel;       
00216   unsigned char m_cVersion;     
00217   unsigned int  m_nSerialNumber; 
00218   unsigned int  m_nChipCount;   
00219   unsigned int  m_nChannels;    
00220   unsigned int  m_nBoardRevision; 
00221   bool          m_fCanHiRes;    
00222   bool          m_fIsHiResMode; 
00223   bool          m_fTriggerMatching; 
00224 
00225 
00226   // Constructors and canonical operations.
00227 
00228 public:
00229   CCAENV1x90(unsigned int nSlot, unsigned int nCrate,
00230              unsigned long nBase); 
00231   ~CCAENV1x90();
00232 private:                        // Copy etc. not allowed.
00233   CCAENV1x90(const CCAENV1x90& rhs);
00234   CCAENV1x90& operator= (const CCAENV1x90& rhs);
00235   int         operator==(const CCAENV1x90& rhs) const;
00236   int         operator!=(const CCAENV1x90& rhs) const;
00237 public:
00238 
00239 
00240   // Selectors:
00241 
00242 
00243 public:
00244 
00245   unsigned int getModel() const { 
00246     return m_nModel;
00247   }
00248   unsigned char getVersion() const { 
00249     return m_cVersion;
00250   }
00251   unsigned int getSerialNumber() const { 
00252     return m_nSerialNumber;
00253   }
00254   unsigned int getChipCount() const { 
00255     return m_nChipCount;
00256   }
00257   unsigned int getChannelCount() const { 
00258     return m_nChannels;
00259   }
00260 
00261   // Class operations:
00262 
00263 public:
00264   unsigned short SR();          
00265 
00266   bool isSetSR(unsigned short bitnum); 
00267   unsigned short ReadCR();      
00268   bool isSetCR(unsigned short bitnum); 
00269 
00270   // Functionality exposed by the control register:
00271 
00272   void Terminate();             
00273   void Unterminate();           
00274   void TerminateWithSwitch();   
00275   void EnableTriggerTagTime();  
00276   void DisableTriggerTagTime(); 
00277  
00278   // Status register functionality:
00279 
00280   bool DataReady();             
00281   bool AlmostFull();            
00282   bool isFull();                
00283   bool isTriggerMatching();     
00284   bool isHeaderEnabled();       
00285   bool isTerminated();          
00286   bool HadError(unsigned int nChip);            
00287   int  ReadResolution();        
00288   bool isPairMode();            
00289   bool WereTriggersLost();      
00290 
00291   void SetGeographicalID(unsigned short int); 
00292   unsigned short GetGeographicalID(); 
00293 
00294   // Key register access functions (sorry that's an SIS -ism).
00295   
00296   void Reset() ;                        
00297   void Clear();                 
00298   void EventReset();            
00299   void Trigger();               
00300 
00301   // Access various register counters.
00302 
00303   unsigned long TriggerCount(); 
00304   unsigned short EventCount();  
00305  
00306 
00307   // Full levels:
00308 
00309   void SetAlmostFullLevel(unsigned int nWords); 
00310   unsigned short  GetAlmostFullLevel(); 
00311   
00312 
00313   // Define what the ECL output is set to be.
00314 
00315   void DefineECLOutput(ECLOutputSelect signal); 
00316   ECLOutputSelect GetECLOutputDefinition(); 
00317 
00318   // State of the event fifo.  This is used to see what
00319   // an event in the buffer memory is going to look like:
00320 
00321   unsigned short EventFIFOCount(); 
00322   unsigned long ReadEventFIFO(); 
00323   bool         isEventFIFOReady(); 
00324   bool         isEventFIFOFull(); 
00325   unsigned short FIFOEventNumber(unsigned long fifoentry); 
00326   unsigned short FIFOWordCount(unsigned long fifoentry); 
00327 
00328 
00329   // Here begin the whole series of operations that involve the
00330   // micro sequencer.  The labels in the text below 
00331   // are taken from the corresponding sections in the hardware
00332   // manual for the board.
00333 
00334   // 5.2 Acquisition modee opcodes:
00335 
00336   void TriggerMatchMode();      
00337   void ContinuousStorageMode(); 
00338   void TransferUntilDone();     
00339   void TransferOneAtATime();    
00340   void LoadDefaultConfig();     
00341   void SaveUserConfig();        
00342   void LoadUserConfig();        
00343   void AutoLoadUserConfig();    
00344   void AutoLoadDefaultConfig(); 
00345 
00346   // 5.3 Trigger  opcodes.
00347 
00348   void SetWindowWidth(unsigned int nWidth);
00350   void SetWindowOffset(int nOffset); 
00351   void SetExtraSearchMargin(unsigned int nMargin); 
00353   void SetRejectMargin(unsigned int nMargin);
00355   void EnableTriggerTimeSubtraction(); 
00356   void DisableTriggerTimeSubtraction(); 
00357   TriggerConfiguration
00358        GetTriggerConfiguration();       
00359   unsigned int GetMatchWindow(TriggerConfiguration config);
00360            int GetWindowOffset(TriggerConfiguration config);
00361   unsigned int GetExtraSearchMargin(TriggerConfiguration config);
00362   unsigned int GetRejectMargin(TriggerConfiguration config);
00363 
00364   bool         isTriggerTimeSubtracted(TriggerConfiguration config);
00365 
00366   //  5.4 Trigger opcodes.
00367   
00368   void     SetEdgeDetectMode(EdgeMode nEdgeMode); 
00369   EdgeMode GetEdgeDetectMode();                   
00370   void     SetIndividualLSB(Resolution nResolution); 
00371   void     SetPairResolutions(LEResolution nLeadingEdge,
00372                               PWResolution nPulseWidth); 
00373   unsigned short GetResolution();                  
00374   Resolution InterpretEdgeResolution(unsigned short nResolution);
00376   LEResolution InterpretLEResolution(unsigned short nResolution);
00378   PWResolution InterpretWidthResolution(unsigned short nResolution);
00380   void SetDoubleHitResolution(DeadTime nDead); 
00381   DeadTime GetDoubleHitResolution(); 
00382 
00383   // 5.5 TDC Readout OPCODES:
00384 
00385   void EnableTDCEncapsulation(); 
00386   void DisableTDCEncapsulation(); 
00387   bool isTDCEncapsulationOn();  
00388   void SetMaxHitsPerEvent(HitMax nHits); 
00389   HitMax GetMaxHitsPerEvent();  
00390   void EnableErrorMark();       
00391   void DisableErrorMark();      
00392   void EnableBypassOnError();   
00393   void DisableBypassOnError();  
00394   void SetErrorEnables(unsigned short nErrors); 
00395   unsigned short GetErrorEnables(); 
00396   void SetL1Size(L1Size nL1Size); 
00397   L1Size GetL1Size();           
00398 
00399 
00400   // 5.6 Channel enable opcodes. nn below is a tdc chip number.
00401   
00402   void EnableChannel(unsigned short nChannel); 
00403   void DisableChannel(unsigned short nChannel); 
00404   void EnableAllChannels();     
00405   void DisableAllChannels();    
00406   void SetChannelEnables(STD(vector)<unsigned short> masks); 
00407   void GetChannelEnables(STD(vector)<unsigned short>& masks); 
00408   void SetChipEnables(unsigned short nChip,
00409                       unsigned int nMask); 
00410   unsigned int GetChipEnables(unsigned short nChip); 
00411 
00412   // 5.7 Adjustment opcodes.
00413   
00414   void SetGlobalOffset(unsigned short nCoarse,
00415                        unsigned short nVernier); 
00416   void ReadGlobalOffset(unsigned short& nCoarse,
00417                         unsigned short& nVernier); 
00418   void SetChannelOffset(unsigned short nChannel,
00419                         unsigned short nOffset); 
00420   unsigned short GetChannelOffset(unsigned int nChannel); 
00421   // V1290 only:
00422 
00423   void CalibrateDelayLine(unsigned short nChip,
00424                           unsigned short Tap1Contact,
00425                           unsigned short Tap2Contact,
00426                           unsigned short Tap3Contact,
00427                           unsigned short Tap4Contat); 
00428   void GetDelayLineCalibration(unsigned short nChip,
00429                                unsigned short& Tap1Contact,
00430                                unsigned short& Tap2Contact,
00431                                unsigned short& Tap3Contact,
00432                                unsigned short& Tap4Contact); 
00433   void SaveDelayLineCalibrations(); 
00434   
00435   // 5.8 Miscellaneous 
00436 
00437   unsigned int GetChipId(unsigned short nChip); 
00438   void GetuCFirmwareInfo(unsigned short& nRevision,
00439                          unsigned short& nDay,
00440                          unsigned short& nMonth,
00441                          unsigned short& nYear); 
00442   unsigned short GetChipErrors(unsigned short nChip); 
00443 
00444   // 5.9 system testing.
00445 
00446   void EnableTestMode(unsigned int nValue); 
00447   void DisableTestMode(); 
00448 
00449   // Data acquisition functions (finally)
00450 
00451   unsigned int ReadData(void* pBuffer,
00452                         unsigned int nMaxLongs);        
00453   unsigned int ReadPacket(void* pBuffer,
00454                           unsigned int nMaxLongs); 
00455   unsigned int ReadValid(void* pBuffer,
00456                          unsigned int nMaxLongs); 
00457 
00458   
00459   void WaitMicroWrite();        
00460 
00461   // utility functions
00462 
00463 protected:
00464   bool ValidBoard(CVmeModule& pROM); 
00465   void BoardProperties(CVmeModule& pROM);
00466   void WriteCR(unsigned short mask); 
00467   void BitSetCR(unsigned short bit); 
00468   void BitClearCR(unsigned short bit); 
00469 
00470   void WriteMicro(unsigned short nWord); 
00471   unsigned short ReadMicro();   
00472   void WriteMicroBlock(void* pWords, 
00473                        unsigned int nWords); 
00474   void ReadMicroBlock(void* pWords,
00475                       unsigned int nWords); 
00476   void MicroTransaction(unsigned short opcode,
00477                         void* pWords,
00478                         unsigned int nWords); 
00479   unsigned long ReadPromLong(CVmeModule& prombase, 
00480                              unsigned long ByteOffset);
00481 
00482 };
00483 #endif

Generated on Wed Sep 17 08:38:09 2008 for NSCL Device support. by  doxygen 1.5.1