Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

TimModuleTest.cxx

Go to the documentation of this file.
00001 //File: TimModuleTest.cxx
00002 
00031 #include <iostream>
00032 #include "TimModule.h"
00033 #include "RCCVmeInterface.h"
00034 
00035 using namespace std;
00036 using namespace SctPixelRod;
00037 
00038 void test();
00039 
00040 int main() {
00041 
00042   try {
00043     test();
00044   }
00045   catch (bad_alloc) {
00046     cout << "Caught bad_alloc" << endl;
00047   }
00048   catch (exception) {
00049     cout << "Caught exception" << endl;
00050   }
00051   catch (TimException x) {
00052     cout << "Caught TimException: " << x.getDescriptor() << " ";
00053     cout << x.getData1() <<     " " << x.getData2() << endl;
00054   }
00055   catch (VmeException x) {
00056     cout << "Caught VmeException:" << endl;
00057 
00058     cout << "Vme ErrorClass " <<        x.getErrorClass() << endl;
00059     cout << "Vme ErrorCode  " << hex << x.getErrorCode()  << endl;
00060 
00061     VmePort *p = x.getPort();
00062 
00063     cout << "Vme ErrorMess " << p->getErrorMessage( x.getErrorCode() ) << endl;
00064     cout << "Vme BusErrors " << p->getBusErrors() << endl;
00065     cout << "Vme LastCode  " << hex << p->getLastErrcode() << endl;
00066     cout << "Vme ErrorMess " << p->getErrorMessage( p->getLastErrcode() );
00067     cout << endl;
00068   }
00069   catch (...) {
00070     cout << "Caught unknown exception" << endl;
00071   }
00072 
00073   return 0;
00074 }
00075 
00076 void test() {
00077 
00078   const UINT32 baseAddr = 0x0D000000;  // VME base address for TIM slot 13
00079   const UINT32  mapSize =    0x10000;  // VME window size
00080 
00081   VmeInterface *vme = new RCCVmeInterface();  // Create VME interface
00082 
00083   TimModule    *tim = new TimModule( baseAddr, mapSize, *vme );  // Create tim
00084 
00085   if (vme == 0 || tim == 0) cout << "Object missing" << vme << tim << endl;
00086 
00087   tim->reset();
00088   tim->initialize();
00089 
00090   hex(cout);
00091   cout << "serial " << tim->getSerialNumber()          << endl;
00092   cout << "TIM ID " << tim->regFetch( TIM_REG_TIM_ID ) << endl;
00093 
00094   tim->issueCommand( TIM_VTRG );
00095   tim->issueVCAL( 99 );
00096   tim->intTrigStart( TIM_MASK_TRIG_10_0KHZ );
00097   tim->intTrigStop();
00098 
00099   const int size = 10;
00100   short unsigned buffer[ TIM_SEQ_SIZE ];
00101   int i;
00102   for (i = 0; i < size; i++) buffer[i] = i << 8;
00103   buffer[4] = TIM_BCR;
00104 
00105   tim->seqLoad(  size, buffer );
00106   tim->seqRun(   size );
00107   tim->seqFetch( size, buffer );
00108 
00109   cout << "buffer:" << endl;
00110   for (i = 0; i < size; i++) {
00111     cout << " " << buffer[i];
00112   }
00113   cout << endl;
00114 
00115   tim->status();
00116 
00117   cout << *tim;
00118 
00119   cout << "soak test..." << endl;
00120   for (i = 0; i < 999999; i++) {
00121     tim->seqLoad(  size, buffer );
00122     tim->seqRun(   size );
00123     tim->seqFetch( size, buffer );
00124   }
00125 
00126   delete tim;
00127   delete vme;
00128 
00129   cout << "Let's provoke a crash!" << endl;
00130   vme = 0;
00131   TimModule( baseAddr, mapSize, *vme );
00132 }

Generated on Thu Dec 15 21:14:42 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5