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

VmePort.h

00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 // 25/03/2002  V 1.0 TM - Data types unsigned, addr_mod->AddrMod, 
00009 //                        namespace added            
00010 //  3/04/2002  V 1.1 PM - Few modifications in the block transfer
00011 //                        methods 
00012 // 18/04/2002  V 1.2 PM - Modification in the interrupt handling
00013 //                        and in the error reporting methods
00014 // 22/04/2002  V 1.3 PM - New methods for blocking and resuming 
00015 //                        interrupt notification and for reading
00016 //                        and setting an interrupt data word           
00017 //             
00018 
00058 #ifndef SCTPIXELROD_VMEPORT_H
00059 #define SCTPIXELROD_VMEPORT_H
00060 
00061 #include <string>
00062 
00063 #include "VmeInterface.h"
00064 
00065 namespace SctPixelRod {
00066 
00067 class VmePort {
00068 public:
00069 
00071   VmePort(unsigned long base, unsigned long size, VmeInterface::AddrMod mod,
00072           VmeInterface &interf) : 
00073           m_baseAddress(base), m_mapSize(size), m_addrMod(mod),
00074           m_interface(interf) {
00075      m_handle = m_interface.registerPort(*this);
00076      m_exceptionTrapping = true;
00077    };
00079   ~VmePort() {
00080     m_interface.deletePort(*this);
00081   };                                                                  
00082 
00084   inline VmeInterface &getInterface() { return m_interface; };         
00086   inline unsigned long getHandle() { return m_handle; };         
00088   inline void *getMap() { return m_interface.getPortMap(m_handle); };         
00090   inline unsigned long getBaseAddress() { return m_baseAddress; };         
00092   inline unsigned long getMapSize() { return m_mapSize; };
00094   inline VmeInterface::AddrMod getAddrMod() { return m_addrMod; };
00096   inline void setExceptionTrapping(bool act) { m_exceptionTrapping = act; };         
00098   inline bool getExceptionTrapping() { return m_exceptionTrapping; };                
00100   inline long getLastErrcode() { return m_interface.getLastErrcode(); };
00102   inline std::string getErrorMessage(const long errcode) { return m_interface.getErrorMessage(errcode); };
00103 
00105   inline long getBusErrors() { return m_interface.getBusErrors(); };
00107   void busErrorReport() { m_interface.busErrorReport(*this); };
00108 
00110   inline unsigned char read8(const unsigned long offset) { 
00111     return m_interface.read8(m_handle, offset);
00112   };  
00113   // Word read (automatic mapping)
00114   inline unsigned short read16(const unsigned long offset){ 
00115     return m_interface.read16(m_handle, offset);
00116   };  
00118   inline unsigned long read32(const unsigned long offset){
00119     return m_interface.read32(m_handle, offset);
00120   };  
00122   inline void write8(const unsigned long offset, const unsigned char value) {
00123     m_interface.write8(m_handle, offset, value);
00124   };   
00126   inline void write16(const unsigned long offset, const unsigned short value) {
00127     m_interface.write16(m_handle, offset, value);
00128   };    
00130   inline void write32(const unsigned long offset, const unsigned long value) {
00131     m_interface.write32(m_handle, offset, value);
00132   };   
00133 
00135   inline void blockRead32(const unsigned long offset, unsigned long *buf, const long len) {
00136     m_interface.blockRead32(*this, offset, buf, len);
00137   };  
00139   inline void blockRead64(const unsigned long offset, unsigned long *buf, const long len) {
00140     m_interface.blockRead64(*this, offset, buf, len);
00141   };   
00143   inline void blockWrite32(const unsigned long offset, const unsigned long *buf, const long len) {
00144     m_interface.blockWrite32(*this, offset, buf, len);
00145   };  
00147   inline void blockWrite64(const unsigned long offset, const unsigned long *buf, const long len) {
00148     m_interface.blockWrite64(*this, offset, buf, len);
00149   };   
00150   
00151   // Interrupt handling
00152   inline void declareInterruptHandler(VmeInterruptHandler &ih) {
00153     m_interface.declareInterruptHandler(ih);
00154   };
00155   inline void cleanInterruptHandlers() {
00156     m_interface.cleanInterruptHandlers();
00157   };
00158   inline void removeInterruptHandler(VmeInterruptHandler &ih) {
00159     m_interface.removeInterruptHandler(ih);
00160   };
00162   inline void reEnableInterrupt() { 
00163     m_interface.reEnableInterrupt();
00164   }; 
00166   void blockInterruptNotification() {
00167     m_interface.blockInterruptNotification();
00168   };
00170   void resumeInterruptNotification() {
00171     m_interface.resumeInterruptNotification();
00172   };
00173   
00174 private:
00175   unsigned long m_handle;
00176   unsigned long m_baseAddress;
00177   unsigned long m_mapSize;
00178   VmeInterface::AddrMod m_addrMod;
00179   VmeInterface &m_interface;
00180   bool m_exceptionTrapping;
00181 };                                             // End of VmePort declaration
00182 
00184 class VmeInterruptHandler {
00185 public:
00187   VmeInterruptHandler(VmePort &port, char vect, int level) : 
00188       m_port(port), m_interruptLevel(level) {
00189     if (level == -1) {
00190       m_interruptVector = 0;
00191       m_interruptSoftVect = vect;
00192     } else {
00193       m_interruptVector = vect;
00194       m_interruptSoftVect = 0;
00195     } 
00196     m_port.declareInterruptHandler(*this); 
00197     m_active = true;
00198   };
00200   virtual ~VmeInterruptHandler() {
00201     m_active = false;
00202     m_port.removeInterruptHandler(*this);
00203   };
00205   virtual void interruptHandler(unsigned char vect, unsigned char softvect, int count) = 0;
00207   inline void activateSoftVector(unsigned char softvect) { 
00208     if (m_interruptSoftVect == 0) m_port.getInterface().activateSoftVector(m_interruptVector, softvect);
00209   };
00211   inline void setInterruptData(long data) {
00212     if (m_interruptSoftVect == 0) m_port.getInterface().setInterruptData(data);
00213   }
00215   inline long getInterruptData() {
00216     return m_port.getInterface().getInterruptData();
00217   }
00219   inline void reEnableInterrupt() { m_port.reEnableInterrupt(); }; 
00221   inline char getInterruptVector() { return m_interruptVector; }
00223   inline char getInterruptSoftVect() { return m_interruptSoftVect; }
00225   inline int getInterruptLevel() { return m_interruptLevel; }
00227   inline void setActive(bool active) { m_active = active; };
00228   inline bool getActive() { return m_active; };
00229   
00230 protected:
00231   VmePort &m_port;
00232   unsigned char m_interruptVector;
00233   unsigned char m_interruptSoftVect;
00234   unsigned int m_interruptLevel;
00235   bool m_active;
00236 };
00237 
00238 } // End namespace SctPixelRod
00239 
00240 #endif // SCTPIXELROD_VMEPORT_H

Generated on Tue Dec 9 10:07:57 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3