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

MdspFlashSave.cxx

00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <ctype.h>
00005 
00006 #include "RodModule.h"
00007 
00008 #include "RCCVmeInterface.h"
00009 
00010 int main(int argc, char *argv[]) {
00011 
00012 using namespace SctPixelRod;
00013 
00014   const unsigned long mapSize=0xc00040;         // Map size
00015   const long numSlaves=4;                       // Number of slaves
00016   long numWords;                                // Number of words to dump
00017   long dspStart, dspEnd;                        // Address limits to dump
00018   
00019   string fileName(""), option;
00020   bool safeMode = false;
00021   int slot = -1;
00022   unsigned long baseAddress;
00023 
00024   if (argc > 1) {
00025     for (int i=1; i<argc; i++) {
00026       option = argv[i];
00027       if (option[0] != '-') break;
00028       switch (option[1]) {
00029         case 'f': {
00030           safeMode = true;
00031           break;
00032         }
00033         case 's': {
00034           slot = atoi(option.substr(2).c_str());
00035           break;
00036         }
00037         default: {
00038           break;
00039         }
00040       }
00041     }
00042   }
00043 
00044 // Prompt for slot number
00045   if (slot < 0 ) {
00046     cout << "Enter slot number (decimal):"; 
00047     cin >> slot;
00048     while ((slot < 1) || (slot > 21)) {
00049       cout << "Slot number out or range [1:21], re-enter: ";
00050       cin >> slot;
00051     }
00052   }
00053   baseAddress = slot << 24;
00054 
00055 // Create VME interface
00056   RCCVmeInterface *vme1 = new RCCVmeInterface();
00057   
00058 // Create RodModule and initialize it
00059   RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00060 
00061   if(!safeMode) {
00062     try{
00063       rod0->initialize();
00064     }
00065     catch (BaseException &b) {
00066       cout << "Exception initing ROD:\n" << b << endl;
00067       cout << "Try the safe mode (-f)\n";
00068       exit(0);
00069     }
00070   } else {
00071     try {
00072       unsigned long int fpgaHold = 0x40;
00073       unsigned long int mdspReset = 0x2;
00074 
00075       cerr << "Put FPGAs on reset hold\n";
00076       // Put FPGAs on hold
00077       rod0->hpiLoad(FPGA_CONTROL_REG_REL_ADDR[1], fpgaHold);
00078       rod0->sleep(1000);
00079       // Reset MDSP 
00080       rod0->hpiLoad(FPGA_CONTROL_REG_REL_ADDR[2], mdspReset);
00081 
00082       rod0->sleep(1000);
00083 
00084       unsigned long hpicValue = 0x00010001;
00085       rod0->hpiLoad(HPIC, hpicValue);
00086 
00087       rod0->sleep(1000);
00088       // mdspSingleRead/Write use HPID not HPID++ (not allowed)
00089 
00090       cerr << "Read from EMIF (1)\n";
00091       for(unsigned long addr = 0x01800000; addr < 0x0180001c; addr+=4) {
00092         unsigned long val = rod0->mdspSingleRead(addr);
00093         cerr << "0x" << hex << addr << ": 0x" << val << dec << endl;
00094       } 
00095 
00096       rod0->sleep(100);
00097 
00098       cerr << "Write CE space setup\n";
00099       rod0->mdspSingleWrite(0x01800004, 0xffff3f03);
00100       rod0->mdspSingleWrite(0x01800008, 0x00000040);
00101       rod0->mdspSingleWrite(0x01800010, 0xffff3f33);
00102       rod0->mdspSingleWrite(0x01800014, 0xffff3f33);
00103 
00104       rod0->sleep(500);
00105 
00106       cerr << "Read from EMIF (2)\n";
00107 
00108       // mdspSingleRead/Write use HPID not HPID++ (not allowed)
00109 
00110       for(unsigned long addr = 0x01800000; addr < 0x0180001c; addr+=4) {
00111         unsigned long val = rod0->mdspSingleRead(addr);
00112         cerr << "0x" << hex << addr << ": 0x" << val << dec << endl;
00113       } 
00114     }
00115     catch (BaseException &b) {
00116       cout << "Exception \"initing\" ROD:\n" << b << endl;
00117       exit(0);
00118     }
00119 
00120     // Two seconds has failed
00121     rod0->sleep(3000);
00122   }
00123 
00124 // get starting address and number of bytes to read
00125 
00126   dspStart = CE1_BASE;
00127   dspEnd = dspStart + 0x80000;
00128 
00129   numWords = (dspEnd +1 - dspStart)/4;
00130 
00131   cout << "Reading from 0x" << hex << dspStart << dec << endl;
00132 
00133 // create buffer and read data
00134   unsigned long * buffer = new unsigned long[numWords];
00135 
00136   if(!safeMode) {
00137     try{
00138       rod0->mdspBlockRead(dspStart, buffer, numWords);
00139     } catch (BaseException &b) {
00140       cout << "Exception Reading from ROD:\n" << b << endl;
00141     }
00142   } else {   // No block reads, no AUTO, if this doesn't work...
00143     try{
00144       for(int i=0; i<numWords; i++) {
00145         buffer[i] = rod0->mdspSingleRead(dspStart + (i*4));
00146       }
00147     } catch (BaseException &b) {
00148       cout << "Exception Reading from ROD:\n" << b << endl;
00149     }
00150   }
00151 
00152   ofstream outFile("MdspFlashSave.bin", ios::binary);
00153   outFile.write((char *)buffer, numWords*4);
00154 
00155 // Clean up before exiting
00156   delete rod0;
00157   delete vme1;
00158 
00159   return 0;  
00160 }

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