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

BocTest.cxx

00001 // Test program for the BOC.
00002 
00003 #include <iostream>
00004 using namespace std;
00005 
00006 #include <ctype.h>
00007 
00008 #include "../RodCrate/BocCard.h"
00009 #include "../../VmeInterface/RCCVmeInterface.h"
00010 #include "parameters.h"
00011 
00012 int main(int argc, char *argv[]) {
00013 
00014 using namespace SctPixelRod;
00015 
00016   unsigned int i,j,k;
00017 
00018   UINT32 localEnable;
00019   UINT32 remoteEnable;
00020 
00021   UINT32 buffer1[100];
00022   UINT32 buffer2[100];
00023 
00024   double monitor[20];
00025 
00026   unsigned long baseAddress;
00027   std::string option;
00028   std::string units;
00029 
00030   long dataLength = -1;
00031   int slot = -1;
00032   int repetitions = 1;
00033 
00034   if (argc > 1) {
00035     for (int i=1; i<argc; i++) {
00036       option = argv[i];
00037       if (option[0] != '-') break;
00038       switch (option[1]) {
00039         case 's': {
00040           slot = atoi(option.substr(2).c_str());
00041           break;
00042         }
00043         case 'l': {
00044           dataLength = atoi(option.substr(2).c_str());
00045           break;
00046         }
00047         case 'r': {
00048           repetitions = atoi(option.substr(2).c_str());
00049           break;
00050         }
00051         default: {
00052           break;
00053         }
00054       }
00055     }
00056   }
00057 
00058 // Prompt for slot number
00059   if (slot < 0 ) {
00060     cout << "Enter slot number (decimal):";
00061     cin >> slot;
00062     while ((slot < 1) || (slot > 21)) {
00063       cout << "Slot number out or range [1:21], re-enter: ";
00064       cin >> slot;
00065     }
00066   }
00067   baseAddress = slot << 24;
00068 
00069 // Create VME interface
00070   RCCVmeInterface *vme1 = new RCCVmeInterface();
00071   
00072 // Create RodModule and initialize it
00073   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00074   try{
00075     rod0->initialize();
00076   }
00077 
00078   catch (HpiException &h) {
00079     hex(cout);
00080     cout << h.getDescriptor() << '\n';
00081     cout << "calcAddr: " << h.getCalcAddr() << ", readAddr: " << 
00082             h.getReadAddr() << '\n';
00083     dec(cout);
00084   };
00085 
00086 
00087 // Now create BocCard
00088 
00089   BocCard* boc0 = rod0->getBocCard();
00090 //
00091 // Initialise
00092 //
00093   boc0->initialize();
00094 //
00095 // Read the "hard-coded" information about the ROD.
00096 
00097   hex(cout);
00098   cout << "BOC, Serial number: " << boc0->getSerialNumber() << endl;
00099   cout << "Manufacturer: " << boc0->getManufacturer() << endl;
00100   cout << "Module type: " << boc0->getModuleType() << endl;
00101   cout << "Firmware revision: " << boc0->getFirmwareRevision() << endl;
00102   cout << "Hardware revision: " << boc0->getHardwareRevision() << endl;
00103   cout << "Status: " << boc0->getBocStatusRegister() << endl << endl;
00104 //
00105   cout << "Information from status method:" << endl;
00106   boc0->status();
00107 //
00108 // Now report the interlock status
00109 //
00110   cout << "Interlock status: " << boc0->getInterlockStatus(&localEnable,&remoteEnable) << endl;
00111   cout << "Local enable: " << localEnable << " Remote enable: " << remoteEnable << endl << endl;
00112 //
00113 // Now check the important functionality. The code is a bit messy,
00114 // but is done this way to try and test as many functions as possible.
00115 //
00116 // Check the Vernier Clock functions
00117 //
00118   boc0->setVernierClockPhase0(10);
00119   boc0->setVernierClockPhase1(6);
00120   i = boc0->getVernierClockPhase0();
00121   j = boc0->getVernierClockPhase1();
00122   cout << "Separate Vernier Clocks(10,6): " << i << " " << j << endl;
00123   boc0->setVernierClockPhases(23);
00124   k = boc0->getVernierClockPhases(&i, &j);
00125   cout << "Combined Vernier Clocks(23): " << k << " " << i << " " << j << endl << endl;
00126 
00127 // Check the thresholds load correctly.
00128 // Set special values in a range of channels.
00129 //
00130   for(i=0;i<BOC_RECEIVE_CHANNELS;i++) {
00131     buffer1[i] = 0xa5;
00132     buffer2[i] = 0;
00133   }
00134 
00135   boc0->setRxThreshold(0,buffer1,BOC_RECEIVE_CHANNELS);
00136 
00137   for(i=0;i<10;i++) {
00138     buffer1[i] = i<<4;
00139   }
00140   boc0->setRxThreshold(5,buffer1,10);
00141   boc0->setRxThreshold(15,10<<4);
00142   boc0->getRxThreshold(0,buffer2,BOC_RECEIVE_CHANNELS);
00143   cout << "Checking Thresholds - only discrepancies reported" << endl;
00144   for(i=0;i<BOC_RECEIVE_CHANNELS;i++) {
00145     if((i<5||i>15)&&(buffer2[i]!=0xa5)) {
00146       cout << dec << i << " : "<< hex << buffer2[i] << " : " << 0xa5 << endl;
00147     }
00148     if((i>4&&i<16)&&(buffer2[i]!=(i-5)<<4)) {
00149       cout << dec << i << " : "<< hex << buffer2[i] << " : " << ((i-5)<<4) << endl;
00150     }
00151   }
00152 // Provoke an exception
00153   try {
00154     boc0->setRxThreshold(15,500);
00155   }
00156   catch (BocException &b) {
00157     cout << "!!BocException when setting threshold" << endl;
00158     cout << b.getDescriptor() << " ";
00159     cout << b.getData1() << " : " << b.getData2() << endl;
00160   }
00161 
00162 // Now check the laser currents set OK.
00163 //
00164 
00165   for(i=0;i<BOC_TRANSMIT_CHANNELS;i++) {
00166     buffer1[i] = 0x5a;
00167     buffer2[i] = 0;
00168   }
00169 
00170   boc0->setLaserCurrent(0,buffer1,BOC_TRANSMIT_CHANNELS);
00171 
00172   for(i=0;i<16;i++) {
00173     buffer1[i] = i<<3;
00174   }
00175   boc0->setLaserCurrent(8,buffer1,16);
00176   boc0->setLaserCurrent(24,16<<3);
00177   boc0->getLaserCurrent(0,buffer2,BOC_TRANSMIT_CHANNELS);
00178   cout << "Checking Laser Currents - only discrepancies reported" << endl;
00179  
00180   for(i=0;i<BOC_TRANSMIT_CHANNELS;i++) {
00181     if((i<8||i>24)&&(buffer2[i]!=0x5a)) {
00182       cout << dec << i << " : "<< hex << buffer2[i] << " : " << 0x5a << endl;
00183     }
00184     if((i>7&&i<25)&&(buffer2[i]!=(i-8)<<3)) {
00185       cout << dec << i << " : "<< hex << buffer2[i] << " : " << ((i-8)<<3) << endl;
00186     }
00187   }
00188 //
00189 // Provoke an exception
00190   try {
00191     boc0->setLaserCurrent(100,0);
00192   }
00193   catch (BocException &b) {
00194     cout << "!!BocException when setting laser current" << endl;
00195     cout << b.getDescriptor() << " ";
00196     cout << b.getData1() << " : " << b.getData2() << endl;
00197   }
00198 
00199 // Check the data delay functions look right.
00200 // Set special values in a range of channels.
00201 //
00202   for(i=0;i<BOC_RECEIVE_CHANNELS;i++) {
00203     buffer1[i] = 0xf;
00204     buffer2[i] = 0;
00205   }
00206 
00207   boc0->setRxDataDelay(0,buffer1,BOC_RECEIVE_CHANNELS);
00208 
00209   for(i=0;i<13;i++) {
00210     buffer1[i] = i;
00211   }
00212   boc0->setRxDataDelay(21,buffer1,13);
00213   boc0->setRxDataDelay(34,13);
00214   boc0->getRxDataDelay(0,buffer2,BOC_RECEIVE_CHANNELS);
00215   cout << "Checking Data Delays - only discrepancies reported" << endl;
00216   for(i=0;i<BOC_RECEIVE_CHANNELS;i++) {
00217     if((i<21||i>34)&&(buffer2[i]!=0xf)) {
00218       cout << dec << i << " : "<< hex << buffer2[i] << " : " << 0xF << endl;
00219     }
00220     if((i>20&&i<35)&&(buffer2[i]!=i-21)) {
00221       cout << dec << i << " : "<< hex << buffer2[i] << " : " << (i-21) << endl;
00222     }
00223   }
00224 
00225 // Provoke an exception
00226   try {
00227     boc0->setRxDataDelay(15,500);
00228   }
00229   catch (BocException &b) {
00230     cout << "!!BocException when setting data delay" << endl;
00231     cout << b.getDescriptor() << " ";
00232     cout << b.getData1() << " : " << b.getData2() << endl;
00233   }
00234 
00235   dec(cout);
00236 //
00237 // Now see what the monitoring channels report
00238 //
00239 
00240   showpoint(cout);
00241   for(i=0;i<12;i++) {
00242     cout << "Monitor channel "<< i << " : " << boc0->getMonitorAdc(i) << 
00243        boc0->getMonitorAdcUnits(i) << endl;
00244   }
00245 
00246   i = boc0->getMonitorAdcCurrentsCount();
00247   cout << i << " currents monitored" << endl;
00248 
00249   j = boc0->getMonitorAdcCurrents(monitor, i, units);
00250   for (i=0;i<j;i++) {
00251     cout << "Channel " << i << " : " << monitor[i] << units << endl;
00252   }
00253 
00254   i = boc0->getMonitorAdcVoltagesCount();
00255   cout << i << " voltages monitored" << endl;
00256 
00257   j = boc0->getMonitorAdcVoltages(monitor, i, units);
00258   for (i=0;i<j;i++) {
00259     cout << "Channel " << i << " : " << monitor[i] << units << endl;
00260   }
00261 
00262   i = boc0->getMonitorAdcTempsCount();
00263   cout << i << " temperatures monitored" << endl;
00264 
00265   j = boc0->getMonitorAdcTemps(monitor, i, units);
00266   for (i=0;i<j;i++) {
00267     cout << "Channel " << i << " : " << monitor[i] << units << endl;
00268   }
00269 
00270   noshowpoint(cout);
00271  
00272 // Delete the BOC, ROD and VME objects before exiting
00273   delete rod0;
00274   delete vme1;
00275 
00276   return 0;  
00277 }
00278 
00279 

Generated on Fri Sep 16 18:01:49 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5