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