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

PrmLoad.cxx

00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <ctype.h>
00005 #include <string>
00006 #include <fstream>
00007 
00008 #include "RodModule.h"
00009 #include "RCCVmeInterface.h"
00010 
00011 int main() {
00012 
00013 using namespace SctPixelRod;
00014 
00015   const unsigned long mapSize=0xc00040;         // Map size
00016   const long numSlaves=4;                       // Number of slaves
00017   long numWords;                                // Number of words to write
00018   std::string binFileName;                      // Name of binary file to load
00019   ifstream binFile;                             // Pointer to binary frile
00020   unsigned long nowAddr;                        // Current location in target
00021   int fileSize;                                 // Size of binary file in bytes
00022   
00023   const unsigned long prmStart=0x00000000;
00024   unsigned long slot, baseAddress;
00025 
00026 // Prompt for slot number
00027   cout << "Enter slot number (decimal):"; 
00028   cin >> slot;
00029   baseAddress = slot << 24;
00030   
00031 // Create VME interface
00032   RCCVmeInterface *vme1 = new RCCVmeInterface();
00033   
00034 // Create RodModule and initialize it
00035   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00036   try{
00037     rod0->initialize();
00038   }
00039   catch (HpiException *h) {
00040     hex(cout);
00041     cout << h->getDescriptor() << '\n';
00042     cout << "calcAddr: " << h->getCalcAddr() << ", readAddr: " << 
00043             h->getReadAddr() << '\n';
00044     dec(cout);
00045   };
00046 
00047   cout << "Enter binary file name, including extension (""q"" to quit): ";
00048   cin >>  binFileName;
00049 
00050   if (binFileName.c_str() == "q") exit(0);
00051   binFile.open(binFileName.c_str(), ios::binary);
00052   if (!binFile.is_open()) {
00053     cout << "Unable to open binary file." << endl;
00054     exit(1);
00055   }
00056   
00057 // Get size of file
00058   binFile.seekg(0, ios::end);           // go to end of file
00059   fileSize = binFile.tellg();          // file size given by current location
00060   binFile.seekg(0, ios::beg);          // go back to beginning of file
00061     
00062 // Create a buffer and read file into itprmSize = fileSize
00063   
00064   UINT8 * buffer;
00065   try {
00066     buffer = new UINT8[fileSize];
00067   }
00068   catch (std::bad_alloc & ba) {
00069     cout << "Unable to allocate buffer for binary file." << endl;
00070     exit(2);
00071   }
00072   binFile.read(buffer, fileSize);
00073   
00074 // write buffer to Proram Reset Manager
00075   rod0->writeBlockToFlashHpi(prmStart, buffer, fileSize);
00076 
00077   cout << fileSize << " bytes written to the Program Reset Manager"<< endl;
00078         
00079 // Clean up before exiting
00080   delete [] buffer;
00081   delete rod0;
00082   delete vme1;
00083 
00084   return 0;  
00085 }
00086 
00087 

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