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

SlinkTest.cxx

00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <ctype.h>
00005 
00006 #include "RodModule.h"
00007 #include "TimModule.h"
00008 
00009 #include "RCCVmeInterface.h"
00010 
00011 int main(int argc, char *argv[]) {
00012 
00013 using namespace SctPixelRod;
00014 
00015   const unsigned long mapSize=0xc00040;         // Map size
00016   const long numSlaves=4;                       // Number of slaves
00017   const int rodReset = 0x40;
00018     
00019   std::string fileName(""), option;
00020   int slot = -1;
00021   unsigned long baseAddress;
00022   unsigned long time = 0;
00023   unsigned long rate = 1;
00024   int pattern = 0;
00025   unsigned long value;
00026   TimModule* tim0;
00027   char use_tim;
00028 
00029   if (argc > 1) {
00030     for (int i=1; i<argc; i++) {
00031       option = argv[i];
00032       if (option[0] != '-') break;
00033       switch (option[1]) {
00034         case 's': {
00035           slot = atoi(option.substr(2).c_str());
00036           break;
00037         }
00038         default: {
00039           break;
00040         }
00041       }
00042     }
00043   }
00044 
00045 // Prompt for slot number
00046   if (slot < 0 ) {
00047     cout << "Enter slot number (decimal):"; 
00048     cin >> slot;
00049     while ((slot < 1) || (slot > 21)) {
00050       cout << "Slot number out or range [1:21], re-enter: ";
00051       cin >> slot;
00052     }
00053   }
00054   baseAddress = slot << 24;
00055 // Prompt for time to run
00056   cout << "Enter time to send events (in seconds):";
00057   cin >> time;
00058 
00059 // Prompt for number of pattern sets
00060   cout << "Enter number of patterns per event:";
00061   cin >> pattern;
00062 //Turn this into the value to set into the register
00063   pattern--;
00064   pattern<<=24;
00065 
00066 //Prompt for TIM use
00067   cout << "Use TIM for triggers (y/n)? ";
00068   cin >> use_tim;
00069 
00070 // Create VME interface
00071   RCCVmeInterface *vme1 = new RCCVmeInterface();
00072   
00073 // Create RodModule and initialize it
00074   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00075   try{
00076     rod0->initialize();
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   if(use_tim == 'y') {
00087 //Create TimModule
00088     cout << "Using TIM for triggers" << endl;
00089     tim0 = new TimModule(0x0d000000,0x10000,*vme1);
00090     tim0->reset();
00091     tim0->initialize();
00092     tim0->regLoad(TIM_REG_ROD_MASK,0xFFFF);
00093     tim0->loadBitSet(TIM_REG_BUSY_EN3,TIM_BIT_BUSY_EN3_ENRBBUSY);
00094     cout << hex << "TIM Busy Enable3 register: " << tim0->regFetch(TIM_REG_BUSY_EN3) << dec << endl;
00095     tim0->loadBitSet(TIM_REG_DEBUG_CTL,TIM_BIT_DEBUGCTL_FVDISABLE);
00096     cout << hex << "TIM Debug Control register: " << tim0->regFetch(TIM_REG_DEBUG_CTL) << dec << endl;
00097 //Set bit 22 in register.
00098     pattern |= 0x400000;
00099   }
00100 
00101 // Reset the ROD
00102   cout << "Reset ROD" << endl;
00103   rod0->hpiLoad(FPGA_CONTROL_REG_REL_ADDR[2], rodReset);
00104   rod0->sleep(5000);
00105 
00106 // Set bits 24-29 in IDE_MEM_CTRL register. This sets the number
00107 // of times the pattern repeats in an event.
00108 // Set bit 20 in IDE_MEM_CTRL register. This sets events going
00109 // at 105kHz. Then sleep for requested period before stopping.
00110 //
00111 
00112   cout << "Start sending events" << endl; 
00113   rod0->hpiLoad(HPIC,0x00010001);
00114 
00115   rod0->mdspSingleWrite(0x404470,pattern);
00116 
00117   value = rod0->mdspSingleRead(0x404470);
00118   cout << "MEM_IDE_CTRL Register contains: " << hex << value << dec << endl;
00119 
00120   rod0->mdspSingleWrite(0x404470,(pattern|0x100000));
00121 
00122   if(use_tim == 'y') {
00123     cout << "Enter TIM Trigger rate in kHz (1, 10 or 100): ";
00124     cin >> rate;
00125     if(rate == 100) {
00126       tim0->intTrigStart(TIM_MASK_TRIG_100_KHZ);
00127     }
00128     else if(rate == 10) {
00129       tim0->intTrigStart(TIM_MASK_TRIG_10_0KHZ);
00130     }
00131     else {
00132       tim0->intTrigStart(TIM_MASK_TRIG_1_00KHZ);
00133     }
00134   }
00135 
00136   rod0->sleep((u_long)(time*1000));
00137 
00138   if(use_tim == 'y') {
00139     tim0->intTrigStop();
00140     rod0->sleep(1000);
00141     value = tim0->fetchL1ID();
00142     cout << "TIM L1ID register = " << value << endl;
00143     value = tim0->regFetch(TIM_REG_BCOUNTL);
00144     cout << "TIM Busy count register = " << value << endl;
00145   }
00146   value = rod0->mdspSingleRead(0x402218);
00147   cout << "EFB_RUNTIME_STAT_REG Register contains: " << hex << value << dec << endl;
00148   rod0->mdspSingleWrite(0x404470,(pattern|0x000000));
00149 
00150 // Clean up before exiting
00151   delete rod0;
00152   delete vme1;
00153 
00154   return 0;  
00155 }
00156 
00157 

Generated on Fri Dec 16 19:38:20 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5