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

FlashDump.cxx

00001 //------------------------------FlashDump------------------------------ 
00002 
00015 #include <iostream>
00016 using namespace std;
00017 
00018 #include <ctype.h>
00019 #include <string>
00020 #include <fstream>
00021 
00022 #include "RodModule.h"
00023 #include "RCCVmeInterface.h"
00024 
00025 int main(int argc, char *argv[]) {
00026 
00027 using namespace SctPixelRod;
00028 
00029   const unsigned long mapSize=0xc00040;         // Map size
00030   const long numSlaves=4;                       // Number of slaves
00031   char response;                                // cin response
00032   std::string binFileName;                      // Name of binary file to load
00033   ifstream binFile;                             // Pointer to binary frile
00034   unsigned long flashAddr;                      // Location in target flash
00035   int numBytes;                                 // Size of binary file in bytes
00036   const unsigned long flashStart[5]={0xe00000, 0xe01000, 0xe80000, 0xed3000, 0xf26000};
00037   unsigned long inputAddr;
00038   
00039   std::string fileName(""), option;
00040   int slot = -1;
00041   unsigned long baseAddress;
00042 
00043   if (argc > 1) {
00044     for (int i=1; i<argc; i++) {
00045       option = argv[i];
00046       if (option[0] != '-') break;
00047       switch (option[1]) {
00048         case 's': {
00049           slot = atoi(option.substr(2).c_str());
00050           break;
00051         }
00052         default: {
00053           break;
00054         }
00055       }
00056     }
00057   }
00058 
00059 // Prompt for slot number
00060   if (slot < 0 ) {
00061     cout << "Enter slot number (decimal):"; 
00062     cin >> slot;
00063     while ((slot < 1) || (slot > 21)) {
00064       cout << "Slot number out or range [1:21], re-enter: ";
00065       cin >> slot;
00066     }
00067   }
00068   baseAddress = slot << 24;
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   cout << "Enter address of target flash memory (without leading 0x) or " << endl;
00087   cout << "     1 for Location File" << endl;
00088   cout << "     2 for ROD Controller" << endl;
00089   cout << "     3 for Formatter" << endl;
00090   cout << "     4 for Event Fragment Builder" << endl;
00091   cout << "     5 for Router" << endl;
00092   cout << "Your choice? ";
00093   cin >> hex >> inputAddr;
00094   if (inputAddr < 6) {
00095     flashAddr = flashStart[inputAddr-1];
00096   }
00097   else {
00098     flashAddr = inputAddr;
00099   }
00100   cout << "Enter number of bytes to read: ";
00101   cin >> dec >> numBytes;
00102 
00103   binFile.open(binFileName.c_str(), ios::binary);
00104     
00105 // Create a buffer
00106   char * buffer;
00107   try {
00108     buffer = new char[numBytes];
00109   }
00110   catch (std::bad_alloc & ba) {
00111     cout << "Unable to allocate buffer." << endl;
00112     exit(1);
00113   }
00114   
00115 // read buffer from flash
00116   for (int i=0; i<numBytes; i++) {
00117     buffer[i]=rod0->readByteFromFlash(flashAddr++, 1);
00118   }
00119 
00120 // print contents to stdout
00121   int itop, tempVal;
00122   const int rowSize = 16;
00123   int numRows = (numBytes-1)/rowSize + 1;
00124   const int rowsPerBlock = 16;
00125   for (int j=0; j<numRows; j++) {
00126     if (j == numRows-1) {
00127       itop = numBytes - j*rowSize;
00128     }
00129     else {
00130       itop = rowSize;
00131     }
00132     for (int i=0; i< itop; i++) {
00133       cout.width(3);
00134       tempVal = int(buffer[i+rowSize*j]);
00135       tempVal = 0x00ff&tempVal;
00136       cout << hex << tempVal << " ";
00137     }
00138     cout << endl;
00139     if (0==(j+1)%rowsPerBlock) { 
00140       if (j+1 >= numRows) break;
00141       cout << "'q' to quit, 'c' to continue:";
00142       cin >> response;
00143       if ('q' == response | 'Q' == response) break;
00144     }
00145   }
00146   dec(cout);
00147  
00148 // Clean up before exiting
00149   delete [] buffer;
00150   delete rod0;
00151   delete vme1;
00152 
00153   return 0;  
00154 }
00155 
00156 

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