/* File: drvPulser.h * Author: Hovanes Egiyan, Jefferson Lab * Date: 12-Apr-2013 * * Purpose: * This module provides the driver support for the asyn device support layer * for the pulser based on CAEN V1495 modules with Ben Raydo's (JLAB) firmware. * * */ #ifndef _DRV_PULSER_HH_ #define _DRV_PULSER_HH_ /************/ /* Includes */ /************/ #include #include #include #include #include #include /* EPICS includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include // include the C driver extern "C" { #include "pulser.h" } #include #include #include #include #include #include #include #include using namespace std; #include "MtxLock.hh" /***************/ /* Definitions */ /***************/ class pulserVAsynPar; // C-function with global scope that calls the member function void readPulserRegisters( void *drvPvt ); // AsynPortDriver for Pulser configuration parameters // it inherits from asynPortDriver class drvPulser : public asynPortDriver { protected: vector dpParVec; // Vector of asyn parameters bool dpExists; // Flag indicating if already exists char* dpBaseAddr; // Base address of the VME module epicsEventId dpEventID; // Event ID for waking up reading thread pthread_mutex_t dpMutex; //! Mutex for an object pthread_mutexattr_t dpMtxAttr; //! Mutex attributes for an object static pthread_mutex_t dpClassMutex; //! Class for this class static pthread_mutexattr_t dpClassMtxAttr; //! Class mutex attributes //! Initialize the mutex for the object void initMutex(); //! Destroy the mutex for the object void closeMutex(); //! Lock the class mutex for this class inline static int classLock() { return pthread_mutex_lock( &dpClassMutex ); } //! Unlock the class mutex for this class inline static int classUnlock() { return pthread_mutex_unlock( &dpClassMutex ); } public: // Name of the driver static string dpDriverName; // Main Constructor to be called when cretion of a driver is requested from IOC script drvPulser( const char *portName, char* baseAddr, vector& parVec ); // Destructor ~drvPulser() {closeMutex();} // These are the methods we override from asynPortDriver virtual asynStatus readUInt32Digital ( asynUser* pasynUser, epicsUInt32* value, epicsUInt32 mask ) ; virtual asynStatus writeUInt32Digital( asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask ); virtual asynStatus readInt32 ( asynUser* pasynUser, epicsInt32* value ) ; virtual asynStatus writeInt32( asynUser *pasynUser, epicsInt32 value ) ; // Print out the report for this AsynPortDriver virtual void report( FILE *fp, int details ); // Returns the base address value inline char* getBaseAddress() { MtxLock objLock(dpMutex); return dpBaseAddr; } // This is the main function for reading. It is executed // in a separate thread and fills the values. void readRegisters(); // Creates new vector of parameters for this driver static vector createParVector(); // Return driver name inline static string getDriverName() { MtxLock classLock(dpClassMutex); return dpDriverName; } //! Initialize global mutex static int initGlobalMutex(); //! Initialize VME bus connection static int initVME(); }; /***********************/ /* Function prototypes */ /***********************/ /* External functions */ /* iocsh functions */ extern "C" { char* drvPulserConfig( const char *portName, int baseAddr ); } #endif