00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013 #include <ctype.h>
00014
00015 #include "RodModule.h"
00016
00017 #include "primParams.h"
00018 #include "RCCVmeInterface.h"
00019 #include "parameters.h"
00020
00021 int main(int argc, char *argv[]) {
00022
00023 using namespace SctPixelRod;
00024
00025 int slaveNumber=-1;
00026 RodPrimList primList(1);
00027 long myTextLength;
00028 TEXT_BUFFER_TYPE myTextType;
00029 PrimState returnPState;
00030 TextBuffState returnTState;
00031 std::string ipramFile("../Dsp/Binary/slaveRun_IPRAM_exp.bin");
00032 std::string idramFile("../Dsp/Binary/slaveRun_IDRAM_exp.bin");
00033 std::string extFile("../Dsp/Binary/slaveRun_xcode_exp.bin");
00034 std::string fileName(""), option;
00035 bool initRod = true;
00036 int slot = -1;
00037
00038 unsigned long baseAddress;
00039
00040 if (argc > 1) {
00041 for (int i=1; i<argc; i++) {
00042 option = argv[i];
00043 if (option[0] != '-') break;
00044 switch (option[1]) {
00045 case 'n': {
00046 initRod = false;
00047 break;
00048 }
00049 case 's': {
00050 slot = atoi(option.substr(2).c_str());
00051 break;
00052 }
00053 case 'v': {
00054 slaveNumber = atoi(option.substr(2).c_str());
00055 break;
00056 }
00057 default: {
00058 break;
00059 }
00060 }
00061 }
00062 }
00063
00064 if (slot < 0 ) {
00065 cout << "Enter slot number (decimal):";
00066 cin >> slot;
00067 while ((slot < 1) || (slot > 21)) {
00068 cout << "Slot number out or range [1:21], re-enter: ";
00069 cin >> slot;
00070 }
00071 }
00072 baseAddress = slot << 24;
00073
00074
00075 RCCVmeInterface *vme1 = new RCCVmeInterface();
00076
00077
00078 RodModule* rod0 = new RodModule(baseAddress, mapSize, *vme1, numSlaves);
00079 if (initRod) {
00080 try{
00081 rod0->initialize();
00082 }
00083 catch (HpiException &h) {
00084 cout << h;
00085 }
00086 catch (VmeException &v) {
00087 cout << "VmeException creating RodModule." << endl;
00088 cout << "ErrorClass = " << v.getErrorClass() << endl;
00089 cout << "ErrorCode = " << v.getErrorCode() << endl;
00090 }
00091 catch (RodException &r) {
00092 cout << r;
00093 }
00094 }
00095
00096
00097 if (slaveNumber < 0 ) {
00098 cout << "Enter slave number (0-3):";
00099 cin >> slaveNumber;
00100 while ((slaveNumber < 0) || (slaveNumber > 3)) {
00101 cout << "Slave number out or range [0:3], re-enter: ";
00102 cin >> slaveNumber;
00103 }
00104 }
00105
00106 try {
00107 rod0->initSlaveDsp(ipramFile, idramFile, extFile, slaveNumber, 'v');
00108 }
00109 catch (RodException & r) {
00110 cout << r.getDescriptor() <<", " << r.getData1() << ", " << r.getData2()
00111 << '\n';
00112 };
00113
00114
00115 char * myTextBuffer;
00116 try {
00117 myTextBuffer= new char[TEXT_BUFF_SIZE];
00118 }
00119 catch (std::bad_alloc) {
00120 cout << "Unable to allocate text buffer in main.";
00121 }
00122
00123
00124
00125 long sdataLength;
00126
00127
00128 sdataLength = 16;
00129 long* echoData;
00130 try {
00131 echoData = new long[sdataLength];
00132 }
00133 catch (std::bad_alloc) {
00134 cout << "Unable to allocate echoData in main.";
00135 }
00136
00137 for (long i=0; i<sdataLength; i++) {
00138 echoData[i] = 0xfeed0000 | i;
00139 }
00140 RodPrimitive* echo;
00141 try {
00142 echo= new RodPrimitive(sdataLength+4, 1, ECHO, R_ECHO, echoData);
00143 }
00144 catch (std::bad_alloc) {
00145 cout << "Unable to allocate Slave DSP ECHO primitive in main.";
00146 }
00147
00148 primList.push_back(*echo);
00149 try {
00150 primList.bufferBuild();
00151 }
00152 catch (PrimListException &p) {
00153 cout << p.getDescriptor() << " ";
00154 cout << p.getData1() << ", " << p.getData2() << "\n";
00155 };
00156
00157
00158 long buffLength = primList.getBufferLength();
00159 unsigned long* slavePrimList;
00160 try {
00161 slavePrimList = new unsigned long[buffLength];
00162 }
00163 catch (bad_alloc) {
00164 cout << "Unable to allocate slavePrimList in main." << endl;
00165 };
00166
00167 unsigned long* bufferStart = primList.getBuffer();
00168 for (int i=0; i< buffLength; i++) {
00169 slavePrimList[i] = bufferStart[i];
00170 }
00171 primList.clear();
00172 delete [] echoData;
00173 delete echo;
00174
00175
00176 long dataLength;
00177 dataLength = 16;
00178 long* mechoData;
00179 try {
00180 mechoData = new long[dataLength];
00181 }
00182 catch (std::bad_alloc) {
00183 cout << "Unable to allocate mechoData in main.";
00184 }
00185
00186 for (long i=0; i<dataLength; i++) {
00187 mechoData[i] = 0xbeef0000 | i;
00188 }
00189 RodPrimitive* mecho;
00190 try {
00191 mecho= new RodPrimitive(dataLength+4, 1, ECHO, R_ECHO, mechoData);
00192 }
00193 catch (std::bad_alloc) {
00194 cout << "Unable to allocate Master DSP ECHO primitive in main.";
00195 }
00196
00197 primList.push_back(*mecho);
00198
00199
00200
00201 long slaveData[4+buffLength];
00202 slaveData[0] = slaveNumber;
00203 slaveData[1] = buffLength;
00204 slaveData[2] = DEFAULT;
00205 slaveData[3] = DEFAULT;
00206 for (int i=0; i< buffLength; i++) {
00207 slaveData[i+4] = slavePrimList[i];
00208 }
00209 RodPrimitive* send0;
00210 try {
00211 send0 = new RodPrimitive(8+buffLength, 0, SEND_SLAVE_LIST,
00212 R_SEND_SLAVE_LIST, slaveData);
00213 }
00214 catch (bad_alloc) {
00215 cout << "Unable to allocate send0 primitive in main." << endl;
00216 };
00217
00218 primList.push_back(*send0);
00219 long startData[3] = {slaveNumber, 1, 1};
00220 RodPrimitive* start0;
00221 try {
00222 start0 = new RodPrimitive(7, 0, START_SLAVE_LIST,
00223 R_START_SLAVE_LIST, startData);
00224 }
00225 catch (bad_alloc) {
00226 cout << "Unable to allocate start0 primitive in main." << endl;
00227 };
00228 primList.push_back(*start0);
00229
00230
00231 long* mechoData2;
00232 try {
00233 mechoData2 = new long[dataLength];
00234 }
00235 catch (std::bad_alloc) {
00236 cout << "Unable to allocate mechoData2 in main.";
00237 }
00238
00239 for (long i=0; i<dataLength; i++) {
00240 mechoData2[i] = 0xcafe0000 | i;
00241 }
00242 RodPrimitive* mecho2;
00243 try {
00244 mecho2= new RodPrimitive(dataLength+4, 1, ECHO, R_ECHO, mechoData2);
00245 }
00246 catch (std::bad_alloc) {
00247 cout << "Unable to allocate Master DSP ECHO primitive in main.";
00248 }
00249
00250 primList.push_back(*mecho2);
00251
00252 try {
00253 primList.bufferBuild();
00254 }
00255 catch (PrimListException *p) {
00256 cout << p->getDescriptor() << " ";
00257 cout << p->getData1() << ", " << p->getData2() << "\n";
00258 };
00259 delete [] mechoData;
00260 delete [] mechoData2;
00261
00262 try {
00263 rod0->sendPrimList(&primList);
00264 }
00265 catch (HpiException *h) {
00266 hex(cout);
00267 cout << h->getDescriptor() << '\n';
00268 cout << "calcAddr: " << h->getCalcAddr() << ", readAddr: " <<
00269 h->getReadAddr() << '\n';
00270 dec(cout);
00271 }
00272 catch (VmeException &v) {
00273 cout << "VmeException in SendPrimList." << endl;
00274 cout << "ErrorClass = " << v.getErrorClass() << endl;
00275 cout << "ErrorCode = " << v.getErrorCode() << endl;
00276 };
00277
00278
00279
00280
00281
00282 do {
00283 try {
00284 returnPState = rod0->primHandler();
00285 }
00286 catch (VmeException &v) {
00287 cout << "VmeException in first primHandler call." << endl;
00288 cout << "ErrorClass = " << v.getErrorClass() << endl;
00289 cout << "ErrorCode = " << v.getErrorCode() << endl;
00290 }
00291 try {
00292 returnTState = rod0->textHandler();
00293 }
00294 catch (VmeException &v) {
00295 cout << "VmeException in first textHandler call." << endl;
00296 cout << "ErrorClass = " << v.getErrorClass() << endl;
00297 cout << "ErrorCode = " << v.getErrorCode() << endl;
00298 }
00299 if (returnTState == TEXT_RQ_SET) {
00300 do {
00301 try {
00302 returnTState = rod0->textHandler();
00303 }
00304 catch (VmeException &v) {
00305 cout << "VmeException in second textHandler call." << endl;
00306 cout << "ErrorClass = " << v.getErrorClass() << endl;
00307 cout << "ErrorCode = " << v.getErrorCode() << endl;
00308 }
00309 } while (returnTState != TEXT_READOUT);
00310 rod0->getTextBuffer(myTextBuffer, myTextLength, myTextType);
00311 rod0->clearTextBuffer();
00312 for (int i=0; i<myTextLength; i++) {
00313 cout << myTextBuffer[i];
00314 if (0==(i+1)%64) cout << endl;
00315 }
00316 cout << endl;
00317 }
00318 } while (returnPState != PRIM_EXECUTING);
00319 do {
00320 try {
00321 returnPState = rod0->primHandler();
00322 }
00323 catch (RodException *r) {
00324 cout << r->getDescriptor() <<", " << r->getData1() << ", " << r->getData2()
00325 << '\n';
00326 }
00327 catch (VmeException &v) {
00328 cout << "VmeException in second primHandler call." << endl;
00329 cout << "ErrorClass = " << v.getErrorClass() << endl;
00330 cout << "ErrorCode = " << v.getErrorCode() << endl;
00331 }
00332 } while ((returnPState != PRIM_WAITING)&&(returnPState != PRIM_IDLE));
00333
00334
00335 RodOutList* outList = rod0->getOutList();
00336
00337
00338 UINT32 outLength = UINT32(outList->getLength());
00339 unsigned long* outBody = outList->getBody();
00340 UINT32 outIndex = UINT32(outBody[1]);
00341 UINT32 outNumPrims = outBody[2];
00342 UINT32 outPrimVersion = outBody[3];
00343 cout << "outLength = " << outLength << ", outIndex = " << outIndex <<
00344 ", outNumPrims = " << outNumPrims << ", outPrimVersion = " <<
00345 outPrimVersion <<'\n';
00346 int outPtr = 4;
00347 for (UINT32 j=0; j<outNumPrims; j++) {
00348 UINT32 primLength = outBody[outPtr++];
00349 UINT32 primIndex = outBody[outPtr++];
00350 UINT32 primId = outBody[outPtr++];
00351 UINT32 primVersion = outBody[outPtr++];
00352 cout << "primLength = " << primLength << ", primIndex = " << primIndex <<
00353 ", primId = 0x" << hex << primId << ", primVersion = " << primVersion << '\n';
00354 cout << "Primitive data: " << endl;
00355 hex(cout);
00356 for (UINT32 i=0; i<primLength-4; i++) {
00357 cout.width(8);
00358 cout << outBody[i+outPtr] <<" ";
00359 if (0 == (i+1)%8) cout << endl;
00360 };
00361 outPtr += primLength-4;
00362 if (0 != (primLength-4)%8) cout << endl;
00363 dec(cout);
00364 };
00365
00366
00367
00368 primList.clear();
00369 delete send0;
00370 delete start0;
00371 delete mecho;
00372 delete mecho2;
00373 delete [] slavePrimList;
00374 delete [] myTextBuffer;
00375 rod0->deleteOutList();
00376
00377
00378 delete rod0;
00379 delete vme1;
00380
00381 return 0;
00382 }
00383
00384