00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TVmeMpx201aModule.hh"
00017 #include "TDataSegment.hh"
00018 #include "TDataElement.hh"
00019
00020 TVmeMpx201aModule::TVmeMpx201aModule( Toff_t offset, Tint mapsize, Tint nch )
00021 : TVmeModule( nch, offset, mapsize, tA16D16 )
00022 {;}
00023
00024 Tvoid TVmeMpx201aModule::SetupCCDmeasurement( Tint rate, Tint nblock, Toff_t offset )
00025 {
00026 Clear();
00027 SetSamplingRate( rate );
00028
00029
00030 SetNumberOfBlock( nblock );
00053
00054
00055 SetDataCaptureMode( tTransientMode );
00056 SetEventSynchronisationMode( tExternalSynchronisationMode );
00057 SetOffsetAddressForDaughterBoard( offset );
00058 EnableAccessToDaughterBoard();
00059
00060 return;
00061 }
00062
00063 TVmeMpx201aModule::TVmeMpx201aModule( const TVmeMpx201aModule& right )
00064 : TVmeModule( right )
00065 {;}
00066
00067 TVmeMpx201aModule::~TVmeMpx201aModule()
00068 {;}
00069
00070 const TVmeMpx201aModule& TVmeMpx201aModule::operator=( const TVmeMpx201aModule& right )
00071 {
00072 *( (TVmeModule*)this ) = *( (TVmeModule*)(&right) );
00073 return *this;
00074 }
00075
00076 Tbool TVmeMpx201aModule::operator==( const TVmeMpx201aModule& right ) const
00077 {
00078 return *( (TVmeModule*)this ) == *( (TVmeModule*)(&right) );
00079 }
00080
00081 Tbool TVmeMpx201aModule::operator!=( const TVmeMpx201aModule& right ) const
00082 {
00083 return *( (TVmeModule*)this ) != *( (TVmeModule*)(&right) );
00084 }
00085
00086 Tint TVmeMpx201aModule::Clear()
00087 {
00088 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 4, 1 );
00089 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 0, 0 );
00090 return theStatus = tStatusSuccess;
00091 }
00092
00093 Tint TVmeMpx201aModule::Update()
00094 {
00095 return Clear();
00096 }
00097
00098 Tint TVmeMpx201aModule::Initialize()
00099 {
00100 return Clear();
00101 }
00102
00103 Tvoid TVmeMpx201aModule::FillData( TDataElement& element, Tint channel )
00104 {
00105
00106
00107 if ( channel < 0 || channel >= theNumberOfChannels ) {
00108 Tcerr << "TVmeMpx201aModule::FillData: invalid ID " << channel << Tendl;
00109 theStatus = -EFAULT;
00110 element.FillData( &theStatus, tTypeInt, 1 );
00111 } else {
00112 TUshort data = Read( channel );
00113 element.FillData( &data, tTypeUnsignedShort, 1 );
00114 }
00115
00116 return;
00117 }
00118
00119 Tvoid TVmeMpx201aModule::SetEventSynchronisationMode( Tsync_t mode )
00120 {
00121 switch ( mode ) {
00122 case tScannerMode:
00123 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 7, 0 );
00124 break;
00125 case tInternalSynchronisationMode:
00126 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 7, 1 );
00127 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 6, 1 );
00128 break;
00129 case tExternalSynchronisationMode:
00130 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 7, 1 );
00131 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 6, 0 );
00132 break;
00133 default:
00134 Tcerr << "TVmeMpx201aModule::SetEventSynchronisationMode: invalid mode" << Tendl;
00135 break;
00136 }
00137
00138 return;
00139 }
00140
00141 Tvoid TVmeMpx201aModule::SetDataCaptureMode( TdataCapture_t mode )
00142 {
00143 switch ( mode ) {
00144 case tTransientMode:
00145 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 5, 1 );
00146 break;
00147 case tContinuousMode:
00148 setBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 5, 0 );
00149 break;
00150 default:
00151 Tcerr << "TVmeMpx201aModule::SetDataCaptureMode: invalid mode" << Tendl;
00152 break;
00153 }
00154 return;
00155 }
00156
00157 TVmeMpx201aModule::Tsync_t TVmeMpx201aModule::GetEventSynchronisationMode() const
00158 {
00159 Tbit d07 = getBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 7 );
00160 Tbit d06 = getBit( (TUshort*)( theBaseAddress + CONTROL_STATUS ), 6 );
00161
00162 if ( d07 == 0 ) {
00163 return tScannerMode;
00164 } else if ( d07 == 1 && d06 == 1 ) {
00165 return tInternalSynchronisationMode;
00166 } else if ( d07 == 1 && d06 == 0 ) {
00167 return tExternalSynchronisationMode;
00168 } else {
00169 return tModeUnknown;
00170 }
00171 }
00172
00173 Tvoid TVmeMpx201aModule::SetNumberOfBlock( Tint nblock )
00174 {
00175 if ( nblock < 0 || nblock > 0x7fff ) {
00176 Tcerr << "TVmeMpx201aModule::SetNumberOfBlock: invalid number" << Tendl;
00177 return;
00178 }
00179 *( (Tshort*)( theBaseAddress + BLOCK_COUNT ) ) = (Tshort)nblock;
00180 return;
00181 }
00182
00183 Tvoid TVmeMpx201aModule::SetSamplingRate( Tint nsample )
00184 {
00185 if ( nsample < 0 || nsample > 0x00ff ) {
00186 Tcerr << "TVmeMpx201aModule::SetSamplingRate: invalid number" << Tendl;
00187 return;
00188 }
00189 *( (Tshort*)( theBaseAddress + SAMPLE_RATE ) ) = (Tshort)nsample;
00190 return;
00191 }
00192
00193 Toff_t TVmeMpx201aModule::GetOffsetAddressForDaughterBoard() const
00194 {
00195 Tshort regval = *( (Tshort*)( theBaseAddress + VME_OFFSET_ADDRESS ) );
00196 regval &= 0xff80;
00197 Toff_t retval = regval;
00198 retval = retval << 16;
00199 return retval;
00200 }
00201
00202 Tvoid TVmeMpx201aModule::SetOffsetAddressForDaughterBoard( Toff_t offset )
00203 {
00204 if ( offset >= (Toff_t)0x00800000 || offset <= (Toff_t)0xff800000 ) {
00205
00206
00207
00208
00209
00210 Tshort s = (Tshort)( ( offset & 0xff800000 ) >> 16 );
00211 *( (Tshort*)( theBaseAddress + VME_OFFSET_ADDRESS ) ) = s;
00212 } else {
00213 Tcerr << "bad address." << Tendl;
00214 }
00215
00216 return;
00217 }
00218
00219 Tvoid TVmeMpx201aModule::SetPage( Tint id )
00220 {
00221 if ( id < 0 || id > 7 ) {
00222 Tcerr << "TVmeMpx201aModule::SetPage: invalid ID" << Tendl;
00223 return;
00224 }
00225 *( (Tshort*)( theBaseAddress + CONTROL_STATUS ) ) |= (Tshort)id;
00226 return;
00227 }
00228
00229 Tint TVmeMpx201aModule::GetMappingSizeOfDaughterBoard() const
00230 {
00231 Tint nblock = GetNumberOfBlock();
00232
00233 return tBlock * nblock * Tsizeof( Tshort );
00234 }
00235
00236 Tvoid TVmeMpx201aModule::NextEventProcedure()
00237 {
00238 DisableAcquisition();
00239 SetMemoryBlockFullFlag( 0 );
00240 SetDataOverFlowFlag( 0 );
00241 EnableSystemFailure();
00242 SetScanCompleteFlag( 0 );
00243 return;
00244 }
00245
00246 TUshort TVmeMpx201aModule::Read( Tint ch )
00247 {
00248 TUshort data = 0x00;
00249 switch ( ch ) {
00250 case tIdRegister:
00251 data = *( (TUshort*)( theBaseAddress + ID ) );
00252 break;
00253 case tDeviceTypeRegister:
00254 data = *( (TUshort*)( theBaseAddress + DEVICE_TYPE ) );
00255 break;
00256 case tControlStatusRegister:
00257 data = *( (TUshort*)( theBaseAddress + CONTROL_STATUS ) );
00258 break;
00259 case tVmeOffsetAddressRegister:
00260 data = *( (TUshort*)( theBaseAddress + VME_OFFSET_ADDRESS ) );
00261 break;
00262 case tPageSetAddressRegister:
00263 data = *( (TUshort*)( theBaseAddress + PAGE_SET ) );
00264 break;
00265 case tReserved:
00266 data = *( (TUshort*)( theBaseAddress + RESERVED ) );
00267 break;
00268 case tTestModeRegister:
00269 data = *( (TUshort*)( theBaseAddress + TEST_MODE ) );
00270 break;
00271 case tTestDataRegister:
00272 data = *( (TUshort*)( theBaseAddress + TEST_DATA ) );
00273 break;
00274 case tInterruptConfigurationRegister:
00275 data = *( (TUshort*)( theBaseAddress + INTERRUPT ) );
00276 break;
00277 case tBlockCounterRegister:
00278 data = *( (TUshort*)( theBaseAddress + BLOCK_COUNT ) );
00279 break;
00280 case tAcquisitionPointerRegister:
00281 data = *( (TUshort*)( theBaseAddress + DAQ_POINTER ) );
00282 break;
00283 case tSampleRateRegister:
00284 data = *( (TUshort*)( theBaseAddress + SAMPLE_RATE ) );
00285 break;
00286 case tFrontPorchRegister:
00287 data = *( (TUshort*)( theBaseAddress + FRONT_PORCH ) );
00288 break;
00289 case tFrameLengthRegister:
00290 data = *( (TUshort*)( theBaseAddress + FRAME_LENGTH ) );
00291 break;
00292 case tRowLengthRegister:
00293 data = *( (TUshort*)( theBaseAddress + ROW_LENGTH ) );
00294 break;
00295 default:
00296 break;
00297 }
00298 data &= 0x00ff;
00299 return data;
00300 }
00301
00302 #ifdef __CLDAQ_ROOT_DLL
00303 ClassImp(TVmeMpx201aModule)
00304 #endif