// drvV792.h // // Asyn driver that inherits from the asynPortDriver class. This is an // adaptation of testAsynPortDriver.cpp written by Mark Rivers. // Started on 5/6/2011, zms // // Addressing via Base Address is supported but not the GEO or MCST/CBLT. //----------------------------------------------------------------------------- #ifndef _drvV792_h #define _drvV792_h #include "asynPortDriver.h" #ifndef SIZE #define SIZE(x) (sizeof(x)/sizeof(x[0])) #endif #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) #endif #ifndef MAX #define MAX(a,b) (((a)>(b))?(a):(b)) #endif #define MAX_ADDR 32 #define DATA 0x0000 #define DSIZE 0x0800 #define BSIZE (DSIZE/4) // buffer size in units of int. #define DTYPEM 0x07000000 // mask for data word type #define DTYPOFST 24 // bit offset to data type field #define HEADM 0x02000000 // header #define CRATEM 0x00ff0000 // mask for crate number field #define CRATEOFF 16 // bit offset to crate number field #define COUNTM 0x00003f00 // mask for event count field #define COUNTOFF 8 // bit offset to event count field #define DATUM 0x00000000 // valid data word #define CHANM 0x001f0000 // mask for chan number (V792) #define CHANOFF 16 // bit offset to channel field #define CHANMN 0x001e0000 // mask for chan number (V792N) #define CHANNOFF 17 // bit offset to channel field (V792N) #define UNDERTH 0x00002000 // under threshold mask #define UNDOFF 13 // under threshold bit offset #define OVERFLO 0x00001000 // over flow mask #define OVEROFF 12 // over flow bit offset #define DATAM 0x00000fff // ADC value mask #define ENDBLK 0x04000000 // end of block #define INVALID 0x06000000 // invalid datum #define BSET1M 0x0098 // bit set/clr 1 mask #define IVECM 0x00ff #define ILEVM 0x0007 #define STAT1M 0x01ff #define CTRL1M 0x0074 #define EVTRM 0x001f #define STAT2M 0x00f6 #define EVCTM 0x00ffffff #define FCLRWM 0x03ff #define BSET2M 0x7fff #define WMEMTM 0x07ff #define CSELM 0x00ff #define TSTEVWM 0x1fff #define IPEDM 0x00ff #define AADM 0x0fff #define BADM 0x0fff typedef enum {v792,v792n} board_t; #define FREV 0x1000 // r/o firmware revision #define BSET1 0x1006 // r/w bit set 1 #define BCLR1 0x1008 // r/w bit clear 1 #define ILEV 0x100a // r/w interrupt level #define IVEC 0x100c // r/w interrupt vector #define STAT1 0x100e // r/o status register 1 #define CTRL1 0x1010 // r/w control register 1 #define ADRH 0x1012 // r/w ADER high #define ADRL 0x1014 // r/w ADER low #define SSRST 0x1016 // w/o single shot reset #define EVTR 0x1020 // r/w event trigger register #define STAT2 0x1022 // r/o status register 2 #define EVCTL 0x1024 // r/o event counter L #define EVCTH 0x1026 // r/o event counter H #define INCEV 0x1028 // w/o increment event #define INCOF 0x102a // w/o increment offset #define LDTST 0x102c // r/w load test register #define FCLRW 0x102e // r/w FCLR window #define BSET2 0x1032 // r/w bit set 2 #define BCLR2 0x1034 // w/o bit clear 2 #define WMEMT 0x1036 // w/o W memory test address #define MEMTWH 0x1038 // w/o memory test word high #define MEMTWL 0x103a // w/o memory test word low #define CSEL 0x103c // r/w crate select #define TSTEVW 0x103e // w/o test event write #define EVCTR 0x1040 // w/o event counter reset #define IPED 0x1060 // r/w #define RTEST 0x1064 // w/r R test address #define SWTRG 0x1068 // w/o software comm (trigger) #define AAD 0x1070 // r/o #define BAD 0x1072 // r/o #define THRSH 0x1080 // r/w threshold memory offset #define OUIMSB 0x8026 // r/o manufacturer id #define OUI 0x802a // r/o #define OUILSB 0x802e // r/o #define VERS 0x8032 // r/o version #define BIDMSB 0x8036 // r/o board id #define BID 0x803a // r/o board id #define BIDLSB 0x803e // r/o board id #define REVS 0x804e // r/o revision #define SNMSB 0x8f02 // r/o serial number #define SNLSB 0x8f06 // r/o serial number #define BS1_BERR 0x008 #define BS1_SADR 0x0010 #define BS1_SRST 0x0080 #define ST1_DRDY 0x0001 #define ST1_GRDY 0x0002 #define ST1_BUSY 0x0004 #define ST1_GBUSY 0x0008 #define ST1_PURGD 0x0020 #define ST1_EVRDY 0x0100 #define CTL1_BLKEND 0x0004 #define CTL1_PRGRST 0x0010 #define CTL1_BEREN 0x0020 #define CTL1_ALIG64 0x0040 #define ST2_BEMPTY 0x0002 #define ST2_BFULL 0x0004 #define ST2_RESERVD 0x0008 #define ST2_DSEL0 0x0010 #define ST2_DSEL1 0x0020 #define ST2_CSEL0 0x0040 #define ST2_CSEL1 0x0080 #define BS2_TMEM 0x0001 #define BS2_OFFL 0x0002 #define BS2_CLRD 0x0004 #define BS2_OVREN 0x0008 #define BS2_LTHEN 0x0010 #define BS2_TACQ 0x0040 #define BS2_SLIDEN 0x0080 #define BS2_STEPTH 0x0100 #define BS2_AUTOIN 0x0800 #define BS2_EMPTEN 0x1000 #define BS2_SLIDSEN 0x2000 #define BS2_ALLTRG 0x4000 #define biStateStr "BI_STATE" #define liFRevStr "LI_FREV" #define liILevStr "LI_ILEV" #define liIVecStr "LI_IVEC" #define liStat1Str "LI_STAT1" #define liStat2Str "LI_STAT2" #define liEvCtrStr "LI_EVCT" #define liAADStr "LI_AAD" #define liBADStr "LI_BAD" #define liOUIStr "LI_OUI" #define liVersStr "LI_VERS" #define liBidStr "LI_BID" #define liRevsStr "LI_REVS" #define liSNStr "LI_SN" #define liOverStr "LI_OVER" #define liUnderStr "LI_UNDER" #define aiChanStr "AI_CHAN" #define loThrshStr "LO_THR" #define liBClr1Str "LI_BCLR1" #define liBClr2Str "LI_BCLR2" #define liBSet1Str "LI_BSET1" #define liBSet2Str "LI_BSET2" #define liCSelStr "LI_CSEL" #define liCtrl1Str "LI_CTRL1" #define liEvTrStr "LI_EVTR" #define liFClrWStr "LI_FCLRW" #define liLDTSTStr "LI_LDTST" #define liIPedStr "LI_IPED" #define loBClr1Str "LO_BCLR1" #define loBClr2Str "LO_BCLR2" #define loBSet1Str "LO_BSET1" #define loBSet2Str "LO_BSET2" #define loCSelStr "LO_CSEL" #define loCtrl1Str "LO_CTRL1" #define loEvTrStr "LO_EVTR" #define loFClrWStr "LO_FCLRW" #define loLDTSTStr "LO_LDTST" #define loIPedStr "LO_IPED" #define loMemTWStr "LO_MEMTW" #define loWMemTStr "LO_WMEMT" #define loTstEvWStr "LO_TSTEVW" #define boSWRstStr "BO_SWRST" #define boSSRstStr "BO_SSRST" #define boIncEvStr "BO_INCEV" #define boIncOfStr "BO_INCOF" #define boEvCtrStr "BO_EVCTR" #define boIntrEnStr "BO_INTREN" #define boSwTrgStr "BO_SWTRG" typedef unsigned char byte; typedef unsigned short word; typedef unsigned int uint; class drvV792 : public asynPortDriver { public: drvV792(const char* port,int c,uint badrs,int a32,int nevt, int nch,const char* btype,uint ivect,uint ilevl); virtual void report( FILE* fp,int level); virtual asynStatus getBounds( asynUser* pau,epicsInt32* lo,epicsInt32* hi); virtual asynStatus readInt32( asynUser* pau,epicsInt32* v); virtual asynStatus writeInt32( asynUser* pau,epicsInt32 v); void readData(); void thisISR(); void rebootCb(); void _afterInit( int flag); protected: // Values used for pasynUser->reason, and indexes into the parameter library. int _biState, _liFRev, _liILev, _liIVec, _liStat1, _liStat2, _liEvCtr, _liAAD, _liBAD, _liOUI, _liVers, _liBid, _liRevs, _liSN, _liOver, _liUnder, _aiChan, _loThrsh, _liBClr1, _liBClr2, _liBSet1, _liBSet2, _liCSel, _liCtrl1, _liEvTr, _liFClrW, _liLDTST, _liIPed, _loBClr1, _loBClr2, _loBSet1, _loBSet2, _loCSel, _loCtrl1, _loEvTr, _loFClrW, _loLDTST, _loIPed, _loMemTW, _loWMemT, _loTstEvW, _boSWRst, _boSSRst, _boIncEv, _boIncOf, _boEvCtr, _boIntrEn,_boSwTrg; #define FRST_COMMAND _biState #define LAST_COMMAND _boSwTrg enum{ ixBiState, ixLiFRev, ixLiILev, ixLiIVec, ixLiStat1, ixLiStat2, ixLiEvCtr, ixLiAAD, ixLiBAD, ixLiOUI, ixLiVers, ixLiBid, ixLiRevs, ixLiSN, ixLiOver, ixLiUnder, ixAiChan, ixLoThrsh, ixLiBClr1, ixLiBClr2, ixLiBSet1, ixLiBSet2, ixLiCSel, ixLiCtrl1, ixLiEvTr, ixLiFClrW, ixLiLDTST, ixLiIPed, ixLoBClr1, ixLoBClr2, ixLoBSet1, ixLoBSet2, ixLoCSel, ixLoCtrl1, ixLoEvTr, ixLoFClrW, ixLoLDTST, ixLoIPed, ixLoMemTW, ixLoWMemT, ixLoTstEvW, ixBoSWRst, ixBoSSRst, ixBoIncEv, ixBoIncOf, ixBoEvCtr, ixBoIntrEn,ixBoSwTrg}; private: asynStatus _configure( int c,uint baddr,int a32,int nevt, int nch,const char* btype,uint ivect,uint ilev); int _probeTest( char* addr,uint off,word test,uint* offu,word* rd); asynStatus _rdReg( uint off,word* v); asynStatus _wtReg( uint off,word v); asynStatus _getEvCt( epicsInt32* v); asynStatus _getOUI( epicsInt32* v); asynStatus _getBid( epicsInt32* v); asynStatus _getSN( epicsInt32* v); void _unpack(); asynUser* _acPvt; const char* _port; uint _badr; int _a32; char* _pmem; uint _dbuf[BSIZE]; // for storing event data int _ndat; // number of data words in _dbuf int _state; // state of last data read int _card; board_t _btype; int _nchan; int _nevnt; int _ovrfl; int _under; int _crate; int _count; uint _ivect; uint _ilevl; epicsInt32 _maxval; uint _chmask; // chan mask in header word int _chboff; // chan bit offset in header word int _thinc; // threshold memory access increment }; #define N_PARAMS (&LAST_COMMAND - &FRST_COMMAND + 1) #endif // _drvV792_h