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