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;
00016 const long numSlaves=4;
00017 long numWords;
00018 std::string binFileName;
00019 ifstream binFile;
00020 unsigned long nowAddr;
00021 int fileSize;
00022
00023 const unsigned long prmStart=0x00000000;
00024 unsigned long slot, baseAddress;
00025
00026
00027 cout << "Enter slot number (decimal):";
00028 cin >> slot;
00029 baseAddress = slot << 24;
00030
00031
00032 RCCVmeInterface *vme1 = new RCCVmeInterface();
00033
00034
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
00058 binFile.seekg(0, ios::end);
00059 fileSize = binFile.tellg();
00060 binFile.seekg(0, ios::beg);
00061
00062
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
00075 rod0->writeBlockToFlashHpi(prmStart, buffer, fileSize);
00076
00077 cout << fileSize << " bytes written to the Program Reset Manager"<< endl;
00078
00079
00080 delete [] buffer;
00081 delete rod0;
00082 delete vme1;
00083
00084 return 0;
00085 }
00086
00087