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

DspDump.cxx

00001 // A program to dump blocks of memory in either Master DSP memory space or a 
00002 // Slave DSP memory space.
00003 
00004 #include <iostream>
00005 using namespace std;
00006 
00007 #include <ctype.h>
00008 
00009 #include "RodModule.h"
00010 
00011 #include "RCCVmeInterface.h"
00012 
00013 int main(int argc, char *argv[]) {
00014 
00015 using namespace SctPixelRod;
00016 
00017   const unsigned long mapSize=0xc00040;         // Map size
00018   const long numSlaves=4;                       // Number of slaves
00019   long numWords;                                // Number of words to dump
00020   long dspStart;                                // Starting address to dump
00021   char response;                                // Y/n response
00022   long dspNumber=-2;                            // DSP number (-1 for MDSP)
00023   std::string ipramFile("../Dsp/Binary/slaveRunBios_IPRAM.bin");
00024   std::string idramFile("../Dsp/Binary/slaveRunBios_IDRAM.bin");
00025   std::string extFile("../Dsp/Binary/slaveRunBios_xcode.bin");
00026 
00027   std::string fileName(""), option;
00028   int slot = -1;
00029   unsigned long baseAddress;
00030 
00031   if (argc > 1) {
00032     for (int i=1; i<argc; i++) {
00033       option = argv[i];
00034       if (option[0] != '-') break;
00035       switch (option[1]) {
00036         case 's': {
00037           slot = atoi(option.substr(2).c_str());
00038           break;
00039         }
00040         case 'v': {
00041           dspNumber = atoi(option.substr(2).c_str());
00042           break;
00043         }
00044         default: {
00045           break;
00046         }
00047       }
00048     }
00049   }
00050 
00051 // Prompt for slot number
00052   if (slot < 0 ) {
00053     cout << "Enter slot number (decimal):"; 
00054     cin >> slot;
00055     while ((slot < 1) || (slot > 21)) {
00056       cout << "Slot number out or range [1:21], re-enter: ";
00057       cin >> slot;
00058     }
00059   }
00060   baseAddress = slot << 24;
00061 
00062 // Create VME interface
00063   RCCVmeInterface *vme1 = new RCCVmeInterface();
00064   
00065 // Create RodModule and initialize it
00066   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00067   try{
00068     rod0->initialize();
00069   }
00070   catch (HpiException *h) {
00071     hex(cout);
00072     cout << h->getDescriptor() << '\n';
00073     cout << "calcAddr: " << h->getCalcAddr() << ", readAddr: " << 
00074             h->getReadAddr() << '\n';
00075     dec(cout);
00076   };
00077   
00078 // get DSP number (-1 for MDSP) starting address and number of bytes to read
00079 
00080 // Get Slave number to read
00081   do {
00082     if (dspNumber < -1 ) {
00083       cout << "Enter DSP number (-1:3):"; 
00084       cin >> dspNumber;
00085       while ((dspNumber < -1) || (dspNumber > 3)) {
00086         cout << "DSP number out or range [-1:3], re-enter: ";
00087         cin >> dspNumber;
00088       }
00089     }
00090 
00091 // Initialize slave DSP
00092   if (dspNumber !=-1) {
00093     rod0->initSlaveDsp(ipramFile, idramFile, extFile, dspNumber);
00094   }
00095 
00096     hex(cin);
00097     cout << "Starting address (hex, without leading 0x): ";
00098     cin >> dspStart;
00099     cout << "Number of words (hex, without leading 0x): ";
00100     cin >> numWords;
00101     dec(cin);
00102   
00103 // create buffer and read data
00104     unsigned long * buffer = new unsigned long[numWords];
00105     
00106     if (dspNumber == -1) {
00107       rod0->mdspBlockRead(dspStart, buffer, numWords);
00108     }
00109     else {
00110       rod0->slvBlockRead(dspStart, buffer, numWords, dspNumber);
00111     }
00112   
00113 // output the data and delete the buffer
00114     hex(cout);
00115     cout.fill('0');
00116     for (int i=0; i<numWords; i+=8) {
00117       cout.width(8);
00118       cout << buffer[i]   << ' ';
00119       cout.width(8);
00120       cout << buffer[i+1] << ' ';
00121       cout.width(8);
00122       cout << buffer[i+2] << ' ';
00123       cout.width(8);
00124       cout << buffer[i+3] << ' ';
00125       cout.width(8);
00126       cout << buffer[i+4] << ' ';
00127       cout.width(8);
00128       cout << buffer[i+5] << ' ';
00129       cout.width(8);
00130       cout << buffer[i+6] << ' ';
00131       cout.width(8);
00132       cout << buffer[i+7] << endl;
00133     }
00134     dec(cout);
00135     cout.fill(' ');
00136     delete [] buffer;
00137     
00138 // do another?
00139     cout << "Do another? [Y/n]: ";
00140     cin >> response;
00141   } while (response != 'n');
00142 
00143 // Clean up before exiting
00144   delete rod0;
00145   delete vme1;
00146 
00147   return 0;  
00148 }
00149 
00150 

Generated on Thu Dec 22 20:17:00 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5