00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TCamacModule.hh"
00024 #include "TCamacCrateController.hh"
00025
00026 TCamacModule::TCamacModule( TCamacCrateController* cc7x00, Tint slot, Tint nch, Tdata_t datalen )
00027 : TModule( nch ),
00028 theCrateController( cc7x00 ), theDataLength( datalen ),
00029 theSlotNumber( slot ), theQ( 0 ), theX( 0 ), theCamacData( 0 )
00030 {;}
00031
00032 TCamacModule::TCamacModule( const TCamacModule& right )
00033 : TModule( right ),
00034 theCrateController( right.theCrateController ),
00035 theDataLength( right.theDataLength ),
00036 theSlotNumber( right.theSlotNumber ),
00037 theQ( 0 ), theX( 0 ), theCamacData( 0 )
00038 {;}
00039
00040 TCamacModule::~TCamacModule()
00041 {;}
00042
00043 const TCamacModule& TCamacModule::operator=( const TCamacModule& right )
00044 {
00045 *( (TModule*)this ) = *( (TModule*)(&right) );
00046 theCrateController = right.theCrateController;
00047 theDataLength = right.theDataLength;
00048 theSlotNumber = right.theSlotNumber;
00049 theQ = right.theQ;
00050 theX = right.theX;
00051 theCamacData = right.theCamacData;
00052 return *this;
00053 }
00054
00055 Tbool TCamacModule::operator==( const TCamacModule& right ) const
00056 {
00057 Tbool retval = Ttrue;
00058 retval &= ( *( (TModule*)this ) == *( (TModule*)(&right) ) );
00059 retval &= ( theCrateController == right.theCrateController );
00060 retval &= ( theSlotNumber == right.theSlotNumber );
00061 retval &= ( theDataLength == right.theDataLength );;
00062 return retval;
00063 }
00064
00065 Tbool TCamacModule::operator!=( const TCamacModule& right ) const
00066 {
00067 Tbool retval = Tfalse;
00068 retval |= ( *( (TModule*)this ) != *( (TModule*)(&right) ) );
00069 retval |= ( theCrateController != right.theCrateController );
00070 retval |= ( theSlotNumber != right.theSlotNumber );
00071 retval |= ( theDataLength != right.theDataLength );;
00072 return retval;
00073 }
00074
00075 Tint TCamacModule::WaitInterrupt( Tint msec )
00076 {
00077 TUint timeout = (TUint)( (Tdouble)HZ/(Tdouble)1000 * (Tdouble)msec );
00078 TUint mask = ( 1 << ( theSlotNumber - 1 ) );
00079 TUint buffer[ 2 ] = { timeout, ~mask };
00080
00081 errno ^= errno;
00082 ioctl( theCrateController -> GetFileDescriptor(), IOC_WAIT_LAM, &buffer );
00083 theStatus = -errno;
00084 theCrateController -> SetStatus( theStatus );
00085
00086 return theStatus;
00087 }
00088
00089 Tint TCamacModule::ReadInterrupt()
00090 {
00091 errno ^= errno;
00092 ioctl( theCrateController -> GetFileDescriptor(), IOC_GET_LAM, &theCamacData );
00093 theStatus = -errno;
00094 theCrateController -> SetStatus( theStatus );
00095
00096 return theStatus;
00097 }
00098
00099 Tint TCamacModule::Clear()
00100 {
00101 return execute( 0, tCamacClear );
00102 }
00103
00104 Tint TCamacModule::Update()
00105 {
00106 return Clear();
00107 }
00108
00109 Tint TCamacModule::Initialize()
00110 {
00111 Clear();
00112 return DisableInterrupt();
00113 }
00114
00115 Tint TCamacModule::TestInterrupt()
00116 {
00117 return execute( 0, tCamacTestInterrupt );
00118 }
00119
00120 Tint TCamacModule::ClearInterrupt()
00121 {
00122 return execute( 0, tCamacClearInterrupt );
00123 }
00124
00125 Tint TCamacModule::EnableInterrupt()
00126 {
00127 return execute( 0, tCamacEnableInterrupt );
00128 }
00129
00130 Tint TCamacModule::DisableInterrupt()
00131 {
00132 return execute( 0, tCamacDisableInterrupt );
00133 }
00134
00135 Tint TCamacModule::Read()
00136 {
00137 return execute( 0, tCamacRead );
00138 }
00139
00140 Tint TCamacModule::Read( Tint subaddress )
00141 {
00142 return execute( subaddress, tCamacRead );
00143 }
00144
00145 Tint TCamacModule::Write( Tint data )
00146 {
00147 theCamacData = (TUint)data;
00148 return execute( 0, tCamacWrite );
00149 }
00150
00151 TUint TCamacModule::generateNAF( Tint n, Tint a, Tint f )
00152 {
00153 TUint naf = 0L;
00154 if ( theCrateController -> IsISA7000() )
00155 naf = ((f & 0x001f)<<16) + ((a & 0x000f)<<8) + (n & 0x001f);
00156 else
00157 naf = (((n-1) & 0x001f)<<9) + ((a & 0x000f)<<5) + (f & 0x0000001f);
00158 return naf;
00159 }
00160
00161 Tint TCamacModule::execute( Tint subaddress, Tint function )
00162 {
00163 TUint naf = generateNAF( theSlotNumber, subaddress, function );
00164 if ( theDataLength == t16bitModule ) {
00165 return execute16bit( naf );
00166 } else if ( theDataLength == t24bitModule ) {
00167 return execute24bit( naf );
00168 } else {
00169 return execute24bit( naf );
00170 }
00171 }
00172
00173 Tint TCamacModule::execute16bit( TUint naf )
00174 {
00175 struct TCamacDriverInterface camacdata;
00176 camacdata._naf = naf;
00177 camacdata._q = 0;
00178 camacdata._x = 0;
00179 camacdata._data._d16 = (TUshort)theCamacData;
00180
00181 errno ^= errno;
00182 ioctl( theCrateController -> GetFileDescriptor(), IOC_CAM16, &camacdata );
00183 theStatus = -errno;
00184 theCrateController -> SetStatus( theStatus );
00185
00186 theQ = (Tint)camacdata._q;
00187 theX = (Tint)camacdata._x;
00188 theCamacData = (TUint)( camacdata._data._d16 );
00189
00190 return theStatus;
00191 }
00192
00193 Tint TCamacModule::execute24bit( TUint naf )
00194 {
00195 struct TCamacDriverInterface camacdata;
00196 camacdata._naf = naf;
00197 camacdata._q = 0;
00198 camacdata._x = 0;
00199 camacdata._data._d24 = theCamacData;
00200
00201 errno ^= errno;
00202 ioctl( theCrateController -> GetFileDescriptor(), IOC_CAM24, &camacdata );
00203 theStatus = -errno;
00204 theCrateController -> SetStatus( theStatus );
00205
00206 theQ = (Tint)camacdata._q;
00207 theX = (Tint)camacdata._x;
00208 theCamacData = camacdata._data._d24;
00209
00210 return theStatus;
00211 }
00212
00213 #ifdef __CLDAQ_ROOT_DLL
00214 ClassImp(TCamacModule)
00215 #endif