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;
00015 const long numSlaves=4;
00016
00017 std::string fileName(""), option;
00018 int slot = -1;
00019 unsigned long baseAddress;
00020
00021 if (argc > 1) {
00022 for (int i=1; i<argc; i++) {
00023 option = argv[i];
00024 if (option[0] != '-') break;
00025 switch (option[1]) {
00026 case 's': {
00027 slot = atoi(option.substr(2).c_str());
00028 break;
00029 }
00030 default: {
00031 break;
00032 }
00033 }
00034 }
00035 }
00036
00037
00038 if (slot < 0 ) {
00039 cout << "Enter slot number (decimal):";
00040 cin >> slot;
00041 while ((slot < 1) || (slot > 21)) {
00042 cout << "Slot number out or range [1:21], re-enter: ";
00043 cin >> slot;
00044 }
00045 }
00046 baseAddress = slot << 24;
00047
00048
00049 RCCVmeInterface *vme1 = new RCCVmeInterface();
00050
00051
00052 RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00053 try{
00054 rod0->initialize();
00055 }
00056 catch (HpiException *h) {
00057 hex(cout);
00058 cout << h->getDescriptor() << '\n';
00059 cout << "calcAddr: " << h->getCalcAddr() << ", readAddr: " <<
00060 h->getReadAddr() << '\n';
00061 dec(cout);
00062 };
00063
00064 unsigned long flashAddr, flashAddrInit = 0xE00100;
00065 UINT8 readData, dataVal, dataInit=0xA0;
00066
00067 flashAddr = flashAddrInit;
00068 dataVal = dataInit;
00069
00070
00071 unsigned long sectorAddress=0xE00000;
00072 rod0->sectorErase(sectorAddress);
00073
00074
00075 for (int i=0; i<16; i++) {
00076 rod0->writeByteToFlash(flashAddr, dataVal++);
00077 flashAddr+=1;
00078 }
00079
00080 flashAddr = flashAddrInit;
00081 dataVal = dataInit;
00082 for (int i=0; i<16; i++) {
00083 readData = rod0->readByteFromFlash(flashAddr, 1);
00084 flashAddr+=1;
00085 if (readData != dataVal++) {
00086 cout << "Byte I/O error" << endl;
00087 }
00088 }
00089
00090
00091 rod0->sectorErase(sectorAddress);
00092
00093
00094 unsigned long blockLength=256;
00095 UINT8 outBlock[blockLength], inBlock[blockLength];
00096 for (int i; i<256; i++) {
00097 outBlock[i] = i;
00098 }
00099
00100 rod0->writeBlockToFlash(flashAddr, outBlock, blockLength);
00101 rod0->readBlockFromFlash(flashAddr, inBlock, blockLength);
00102
00103 for (unsigned int i=0; i<blockLength; i++) {
00104 if (inBlock[i] != outBlock[i]) {
00105 cout << "Block I/O error." << endl;
00106 }
00107 }
00108
00109
00110 rod0->chipEraseHpi();
00111
00112
00113 delete rod0;
00114 delete vme1;
00115
00116 return 0;
00117 }
00118
00119