00001 /* 00002 # 00003 # This software is Copyright by the Board of Trustees of Michigan 00004 # State University (c) Copyright 2008. 00005 # 00006 # You may use this software under the terms of the GNU public license 00007 # (GPL). The terms of this license are described at: 00008 # 00009 # http://www.gnu.org/licenses/gpl.txt 00010 # 00011 # Author: 00012 # Eric Kasten 00013 # NSCL 00014 # Michigan State University 00015 # East Lansing, MI 48824-1321 00016 # 00017 */ 00018 00019 #ifndef CADC2530_H 00020 #define CADC2530_H 00021 00022 #include <stdio.h> 00023 #include <sys/types.h> 00024 #include <sys/stat.h> 00025 #include <sys/mman.h> 00026 #include <errno.h> 00027 #include <fcntl.h> 00028 #include <unistd.h> 00029 #include <signal.h> 00030 #include <sys/ioctl.h> 00031 #include <string> 00032 00033 #ifndef __CVMEINTERFACE_H 00034 #include <CVMEInterface.h> 00035 #endif 00036 00037 #ifndef HAVE_VME_MAPPING 00038 #include <VmeModule.h> // Needed to access registers via peek/poke. 00039 #endif 00040 00053 class CADC2530 { 00054 // ------------------------------------------------------------ 00055 // Public members 00056 public: 00057 CADC2530(int crateNum = 0, long nBase = 0); 00058 CADC2530(const CADC2530& card); 00059 ~CADC2530(); 00060 00061 static bool checkCard(int,long,unsigned short&,unsigned short&); 00062 static unsigned short volt2lld(double); 00063 static unsigned short volt2uld(double); 00064 00065 CADC2530& operator=(const CADC2530&); 00066 00067 const std::string& toString(); 00068 00069 int readListEvents(void*,int&); 00070 int readHistogramChannel(void*,int); 00071 00072 unsigned short cardType(); 00073 unsigned short manufacturerId(); 00074 00075 void clearHistogramMemory(); 00076 void clearMemory(); 00077 void resetCard(); 00078 00079 void clearListAddress(); 00080 unsigned int getListAddress(); 00081 00082 void arm(); 00083 void disarm(); 00084 bool isArmed(); 00085 00086 void modeHistogram(bool); 00087 void modeGate(); 00088 00089 void resetCSR(); 00090 void fastClear(); 00091 00092 bool isBusy(); 00093 bool dataReady(); 00094 bool hasInterrupt(); 00095 00096 void enableInterrupt(); 00097 void disableInterrupt(); 00098 00099 void enableGate(); 00100 void disableGate(); 00101 00102 void enableZeroCnv(); 00103 void disableZeroCnv(); 00104 00105 void enableCalibration(); 00106 void disableCalibration(); 00107 00108 void enableSlidingScale(); 00109 void disableSlidingScale(); 00110 00111 void setIPL(unsigned short); 00112 unsigned short getIPL(); 00113 00114 unsigned short getCSR(); 00115 00116 void dataReadyOnEvent(); 00117 void dataReadyOnFullness(); 00118 00119 void setLLD(unsigned short); 00120 unsigned short getLLD(); 00121 void setULD(unsigned short); 00122 unsigned short getULD(); 00123 00124 void setInterruptVector(unsigned short); 00125 unsigned short getInterruptVector(); 00126 void setInterruptMask(unsigned short); 00127 unsigned short getInterruptMask(); 00128 00129 void clearFullnessFlags(); 00130 unsigned short getFullnessFlags(); 00131 bool isChannelFull(unsigned short); 00132 bool channelHasData(unsigned short); 00133 bool isListFull(); 00134 bool isListHalfFull(); 00135 00136 unsigned int getEventCounter(); 00137 void clearEventCounter(); 00138 00139 // Calibration and test methods 00140 unsigned short getCTR(); 00141 void resetCTR(); 00142 void setCTRchannel(unsigned short); 00143 unsigned short getCTRchannel(); 00144 void enableAutoFastClear(); 00145 void disableAutoFastClear(); 00146 void enableMUXswitch(); 00147 void disableMUXswitch(); 00148 void enableCompensation(); 00149 void disableCompensation(); 00150 void setSSTR(unsigned short); 00151 unsigned short getSSTR(); 00152 00153 // ------------------------------------------------------------ 00154 // Protected members 00155 protected: 00156 int my_nCrate; 00157 unsigned long my_nBase; 00158 unsigned long my_nMemOffset; 00159 unsigned short my_nCardId; 00160 unsigned short my_nCardType; 00161 void* my_nModFd; 00162 void* my_nMemFd; 00163 bool my_eventmode; 00164 unsigned int my_cureventpos; 00165 00166 #ifndef HAVE_VME_MAPPING 00167 CVmeModule* my_pModule; 00168 CVmeModule* my_pMemory; 00169 #else 00170 volatile unsigned short *my_pModule; 00171 volatile unsigned int *my_pMemory; 00172 #endif 00173 00174 void mapModule(); 00175 void mapMemory(); 00176 void destroyModule(); 00177 void destroyMemory(); 00178 00179 void destroyCard(); 00180 void mapCard(); 00181 00182 void slotInit(); 00183 00184 int readListEvent(void*,int); 00185 00186 unsigned long calcMemoryOffset(unsigned long); 00187 unsigned long setMemoryOffset(unsigned long); 00188 00189 void setCSR(unsigned short); 00190 void setCSRbits(unsigned short,unsigned short); 00191 void resetCSRbits(unsigned short); 00192 00193 void setCTR(unsigned short); 00194 void setCTRbits(unsigned short,unsigned short); 00195 void resetCTRbits(unsigned short); 00196 }; 00197 00198 #endif