/* File: drvuScopeBiasBoard.hh * Author: Hovanes Egiyan, Jefferson Lab * Date: 05-Jan-2014 * * Purpose: * This module provides the driver support for the asyn device support layer * for the microscope control board. * */ #ifndef _DRV_uScopeBiasBoard_HH_ #define _DRV_uScopeBiasBoard_HH_ /************/ /* Includes */ /************/ #include #include #include #include #include #include /* EPICS includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // include the header file for my custom simple mutex manipulation class #include "MtxLock.hh" // Include header file for the UConn control board driver // In UConn driver the boards are referred to as control boards // while in this asyn driver the boards are referred to as bias boards #include "UConnCtrlBoard.hh" #include "UConnBiasChannel.hh" /***************/ /* Definitions */ /***************/ // Board-wise parameters #define uScopeBiasBoardAddressString "BIAS_BOARD_ADDRESS" #define uScopeBiasBoardPortString "BIAS_BOARD_PORT" #define uScopeBiasBoardTempString "BIAS_BOARD_TEMPERATURE" #define uScopeBiasBoardStatusString "BIAS_BOARD_STATUS" #define uScopeBiasBoardChanNumbString "BIAS_BOARD_NCHAN" // Channel-wise parameters #define uScopeBiasBoardChanAddrString "BIAS_CHAN_ADDRESS" #define uScopeBiasBoardChanMaxVoltString "BIAS_CHAN_MAX_VOLT" #define uScopeBiasBoardChanSetPointString "BIAS_CHAN_SET_POINT" #define uScopeBiasBoardChanRampUpString "BIAS_CHAN_RAMP_UP" #define uScopeBiasBoardChanRampDownString "BIAS_CHAN_RAMP_DOWN" #define uScopeBiasBoardChanTempString "BIAS_CHAN_TEMP" #define uScopeBiasBoardChanStatString "BIAS_CHAN_STATUS" #define uScopeBiasBoardChanEnableString "BIAS_CHAN_ENABLE" // C-function with global scope that calls the member function void readBoardParameters( void *drvPtr ); // AsynPortDriver for uScopeBiasBoard configuration parameters // it inherits from asynPortDriver class drvuScopeBiasBoard: public asynPortDriver { protected: string dubbIP; //! IP name/address of the uScopeBiasBoard control board bool dubbExists; //! Flag indicating if already exists epicsEventId dubbEventID; //! Event ID for waking up reading thread UConnCtrlBoard* dubbBoard; //! UConnCtrlBoard crate object that handles all board related operations string dubbMbbPrefix; //! MBB prefix for configuring EPICS DB vector dubbChannelsInBoard; //! Vector of channels in the board pthread_mutex_t dubbMutex; //! Mutex for an object pthread_mutexattr_t dubbMtxAttr; //! Mutex attributes for an object static pthread_mutex_t dubbClassMutex; //! Class mutex for this class static pthread_mutexattr_t dubbClassMtxAttr; //! Class mutex attributes static map dubbPortMap; //! Map containing pointers to all ports // static string dubbDirNameDB; //! Directory name where DB file template for EPICS records lives static string dubbBoardFileNameDB; //! DB template file name for EPICS records referring to boards static string dubbChannelFileNameDB; //! DB template file name for EPICS records referring to channels static string dubbDriverName; //! Asyn driver name static map dubbMbbPrefixMap; //! Map to keep mbbi/mbbo string number assignment for boards static vector dubbMbbPrefixVec; //! Vector to keep track of insertion order for dubbMbbPrefixVec static unsigned dubbMaxBoards; //! Maximum number of boards allowed by the driver //! 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( &dubbClassMutex ); } //! Unlock the class mutex for this class inline static int classUnlock() { return pthread_mutex_unlock( &dubbClassMutex ); } public: // Main Constructor to be called when creation of a driver is requested from IOC script drvuScopeBiasBoard( const char *ipAddress, const char *portName, int maxNumberOfChannels ); // Destructor ~drvuScopeBiasBoard(); // These are the methods we override from asynPortDriver // asynStatus readInt32( asynUser* pasynUser, epicsInt32* value ); virtual asynStatus readUInt32Digital( asynUser* pasynUser, epicsUInt32* value, epicsUInt32 mask ); virtual asynStatus readFloat64( asynUser *pasynUser, epicsFloat64 *value ); virtual asynStatus readOctet( asynUser *pasynUser, char *value, size_t maxChars, size_t *nActual, int *eomReason ); virtual asynStatus writeUInt32Digital( asynUser* pasynUser, epicsUInt32 value, epicsUInt32 mask ); virtual asynStatus writeFloat64( asynUser *pasynUser, epicsFloat64 value ); // Print out the report for this AsynPortDriver virtual void report( FILE *fp, int details ); // Returns the base address value inline string getIP() { MtxLock objLock( dubbMutex ); return dubbBoard->GetAddress(); } // This is the main function for reading. It is executed // in a separate thread and fills the values. void readBoardParameters(); // Method to dynamically load EPICS DB records using templates int loadRecords(); static map initMbbMap( vector& preixVec ); static vector initPrefixVector(); inline UConnCtrlBoard* getCtrlBoard() { MtxLock objLock( dubbMutex ); return dubbBoard; } inline bool exists() { MtxLock objLock( dubbMutex ); return dubbExists; } static map getPortMap() { MtxLock classLock( dubbClassMutex ); return dubbPortMap; } //! Initialize global mutex static int initGlobalMutex(); #define FIRST_uScopeBiasBoard_PARAM uScopeBiasBoardAddress_ // // Board-wise parameters int uScopeBiasBoardAddress_ ; int uScopeBiasBoardPort_ ; int uScopeBiasBoardTemp_ ; int uScopeBiasBoardStatus_ ; int uScopeBiasBoardChanNumb_ ; // Channel-wise parameters int uScopeBiasBoardChanAddr_ ; int uScopeBiasBoardChanMaxVolt_ ; int uScopeBiasBoardChanSetPoint_; int uScopeBiasBoardChanRampUp_ ; int uScopeBiasBoardChanRampDown_; int uScopeBiasBoardChanTemp_ ; int uScopeBiasBoardChanStat_ ; int uScopeBiasBoardChanEnable_ ; // #define LAST_uScopeBiasBoard_PARAM uScopeBiasBoardChanEnable_ #define NUM_uScopeBiasBoard_PARAMS (&LAST_uScopeBiasBoard_PARAM- &FIRST_uScopeBiasBoard_PARAM + 1) }; /***********************/ /* Function prototypes */ /***********************/ /* External functions */ /* iocsh functions */ extern "C" { char* drvuScopeBiasBoardConfig( const char *ipAddress, const char* portName, int maxNumOfChans ); } #endif