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

FlashSave.cxx

00001 //------------------------------FlashSave------------------------------ 
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 using namespace SctPixelRod;
00026 
00027 const unsigned long flashStart[5]={0xe00000, 0xe01000, 0xe80000, 0xed3000, 0xf26000};
00028 const long flashSize[5] = {24, 495204, 336688, 336680, 234456};
00029 std::string flashName[5] = {"Location", "ROD Controller", "Formatter", 
00030                             "Event Fragment Builder", "Router"};
00031 std::string flashFileName[5] = {"Location", "RODController", "Formatter", 
00032                             "EventFragmentBuilder", "Router"};
00033 
00034 
00035 
00036 int main(int argc, char *argv[]) {
00037   const unsigned long mapSize=0xc00040;         // Map size
00038   const long numSlaves=4;                       // Number of slaves
00039 
00040 //   char response;                                // cin response
00041 //   std::string binFileName;                      // Name of binary file to load
00042 //   ifstream binFile;                             // Pointer to binary frile
00043 //   unsigned long flashAddr;                      // Location in target flash
00044 //   int numBytes;                                 // Size of binary file in bytes
00045 //   const unsigned long flashStart[5]={0xe00000, 0xe01000, 0xe80000, 0xed3000, 0xf26000};
00046 //   unsigned long inputAddr;
00047 
00048 //   std::string fileName(""), option;
00049   int slot = -1;
00050   unsigned long baseAddress;
00051 
00052   if (argc > 1) {
00053     for (int i=1; i<argc; i++) {
00054       string option = argv[i];
00055       if (option[0] != '-') break;
00056       switch (option[1]) {
00057         case 's': {
00058           slot = atoi(option.substr(2).c_str());
00059           break;
00060         }
00061         default: {
00062           break;
00063         }
00064       }
00065     }
00066   }
00067 
00068 // Prompt for slot number
00069   if (slot < 0 ) {
00070     cout << "Enter slot number (decimal):"; 
00071     cin >> slot;
00072     while ((slot < 1) || (slot > 21)) {
00073       cout << "Slot number out or range [1:21], re-enter: ";
00074       cin >> slot;
00075     }
00076   }
00077   baseAddress = slot << 24;
00078   
00079 // Create VME interface
00080   RCCVmeInterface *vme1 = new RCCVmeInterface();
00081   
00082 // Create RodModule and initialize it
00083   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00084   try{
00085     rod0->initialize();
00086   }
00087   catch (HpiException *h) {
00088     hex(cout);
00089     cout << h->getDescriptor() << '\n';
00090     cout << "calcAddr: " << h->getCalcAddr() << ", readAddr: " << 
00091             h->getReadAddr() << '\n';
00092     dec(cout);
00093   };
00094 
00095   for(int f=0; f<5; f++) {
00096     string fname(flashFileName[f] + ".bin");
00097     cout << "Saving " << flashName[f] << " To " << fname << endl;
00098 
00099     ofstream outFile(fname.c_str(), ios::binary);
00100 //   binFile.open(binFileName.c_str(), ios::binary);
00101 
00102     int byteLength = flashSize[f];
00103     unsigned int location = flashStart[f];
00104     
00105 // Create a buffer
00106     char * buffer;
00107     try {
00108       buffer = new char[byteLength];
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<byteLength; i++) {
00117       buffer[i]=rod0->readByteFromFlash(location++, 1);
00118     }
00119 
00120     // Save file 
00121     outFile.write(buffer, byteLength);
00122 
00123     
00124     delete [] buffer;
00125   }
00126 
00127   delete rod0;
00128   delete vme1;
00129 
00130   return 0;  
00131 }
00132 
00133 

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