00001
00002
00003 #ifndef SCTPIXELROD_RODMODULE_H
00004 #define SCTPIXELROD_RODMODULE_H
00005
00006 #include <fstream>
00007 #include <iostream>
00008 #include <string>
00009 #include <ctime>
00010 #include <new>
00011
00012 #include "RodPrimitive.h"
00013 #include "RodPrimList.h"
00014 #include "../../VmeInterface/VmeInterface.h"
00015 #include "../../VmeInterface/VmePort.h"
00016 #include "../../VmeInterface/VmeModule.h"
00017 #include "../CommonWithDsp/processor.h"
00018 #include "RodRegisterBits.h"
00019 #include "../CommonWithDsp/smSendTxtBuff.h"
00020 #include "RodDspAddresses.h"
00021 #include "RodVmeAddresses.h"
00022 #include "RodOutList.h"
00023 #include "../CommonWithDsp/txtBuffer.h"
00024
00025 namespace SctPixelRod {
00026
00027 enum TextBuffState {TEXT_IDLE, TEXT_RQ_SET, TEXT_READOUT, TEXT_ERROR};
00028 enum PrimState {PRIM_IDLE, PRIM_LOADED, PRIM_EXECUTING, PRIM_WAITING, PRIM_PAUSED};
00029 enum TEXT_BUFFER_TYPE {TEXT_ERR, TEXT_INFO, TEXT_DIAG, TEXT_XFER, TEXT_UNDEF};
00030 enum HpidMode {DYNAMIC, AUTO, NO_AUTO};
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class NoImageFile {
00045 public:
00046 NoImageFile( std::string fileName) {m_fileName=fileName;};
00047 std::string getFileName() {return m_fileName;};
00048
00049 private:
00050 std::string m_fileName;
00051 };
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class HpiException {
00065 public:
00066 HpiException( std::string descriptor, unsigned long calcAddr, unsigned long readAddr);
00067 std::string getDescriptor() {return m_descriptor;};
00068 unsigned long getCalcAddr() {return m_calcAddr;};
00069 unsigned long getReadAddr() {return m_readAddr;};
00070
00071 private:
00072 std::string m_descriptor;
00073 unsigned long m_calcAddr;
00074 unsigned long m_readAddr;
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 class RodException {
00089 public:
00090 RodException( std::string descriptor);
00091 RodException( std::string descriptor, unsigned long data1);
00092 RodException( std::string descriptor, unsigned long data1, unsigned long data2);
00093 std::string getDescriptor() {return m_descriptor;};
00094 unsigned long getData1() {return m_data1;};
00095 unsigned long getData2() {return m_data2;};
00096
00097 private:
00098 std::string m_descriptor;
00099 unsigned long m_numData;
00100 unsigned long m_data1;
00101 unsigned long m_data2;
00102 };
00103
00104
00105
00106 /*! @class RodModule
00107 *
00108 * @brief This is a derived class providing the software interface for VME ROD modules.
00109 *
00110 * This is the implementation of a ROD class derived from the VmeModules base class
00111 * It should be the sole interface for VME communication with the ROD modules.
00112 *
00113 * @author Tom Meyer (meyer@iastate.edu) - originator
00114 */
00115
00116 class RodModule : public VmeModule {
00117
00118 public:
00119
00120
00121 RodModule( unsigned long baseAddr, unsigned long mapSize, VmeInterface & ourInterface,
00122 long numSlaves) throw (RodException&, VmeException &);
00123 RodModule(const RodModule& rhs);
00124 RodModule &operator=(const RodModule & rhs);
00125 virtual ~RodModule();
00126
00127
00128
00129 unsigned long getBaseAddress() {return m_baseAddress; }
00130 long getSlot() const { return m_slot; }
00131 unsigned long getSerialNumber() {return m_serialNumber;};
00132 void setNumSlaves( long numSlaves) { m_numSlaves = numSlaves; }
00133 long getNumSlaves() const { return m_numSlaves; }
00134 void setFinBufferSize( long finBufferSize) { m_finBufferSize = finBufferSize;}
00135 long getFinBufferSize() const { return m_finBufferSize; }
00136 std::string getMasterImageName() {return m_masterImageName; }
00137 std::string getslaveEmifName(long slaveNum) {return m_slaveEmifName[slaveNum];}
00138 std::string getslaveIpramName(long slaveNum) {return m_slaveIpramName[slaveNum];}
00139 std::string getslaveIdramName(long slaveNum) {return m_slaveIdramName[slaveNum];}
00140 std::string getslaveExtName(long slaveNum) {return m_slaveExtName[slaveNum];}
00141 unsigned long getVmeCommandRegVal(long regNum) {
00142 return m_vmeCommandReg[regNum];
00143 };
00144 VmePort* getVmePort() {return m_myVmePort; };
00145 void setOutList(RodOutList* outList) {m_myOutList = outList;};
00146 RodOutList* getOutList() {return m_myOutList;};
00147 PrimState getPrimState() {return m_myPrimState;};
00148 TextBuffState getTextState() {return m_myTextState;};
00149
00150 long getMode() { return long(m_txtBuffer.mode);};
00151 long getOverwrite() {return long(m_txtBuffer.overwrite);};
00152 long getOverflow() {return long(m_txtBuffer.overflow);};
00153 long getWrap() {return long(m_txtBuffer.wrap);};
00154 TEXT_BUFFER_TYPE getTextBufferType() {return m_textType;};
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 void initialize() throw (RodException &, VmeException &);
00170
00171
00172
00173
00174 void reset() throw (RodException&, VmeException &);
00175
00176
00177
00178
00179
00180 void status () throw();
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 void initSlaveDsp(const std::string & emifFile, const std::string & ipramFile,
00191 const std::string & idramFile,const std::string & extFile,
00192 const long slaveNumber) throw(RodException&, NoImageFile&, VmeException &);
00193
00194
00195
00196
00197
00198 void loadSlaveImage(const std::string & filename, const unsigned long address,
00199 const long slaveNumber, char opt='n')
00200 throw (NoImageFile &, RodException &, VmeException &);
00201
00202
00203
00204
00205 void startSlave(const long slaveNumber, char mode='s') throw(VmeException &);
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 void synchSendPrim(RodPrimitive & prim) throw (RodException &, VmeException &) ;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 void sendPrimList(RodPrimList *l) throw(VmeException &) ;
00229
00230
00231
00232
00233
00234 PrimState primHandler() throw (RodException &, VmeException &);
00235
00236
00237 inline bool getDspAck() {return readRodStatusBit(0, DSPACK);};
00238
00239
00240 inline void setInListReady(){setVmeCommandRegBit(INLISTRDY); return;};
00241
00242
00243 void deleteOutList() throw() ;
00244
00245
00246
00247
00248 inline long getAllTextBuffBits() {
00249 unsigned long regValue;
00250 regValue = readRodStatusReg(0);
00251 return (regValue>>TEXT_BUFF_NOT_EMPTY[0] & 0xF);
00252 };
00253
00254
00255
00256
00257
00258
00259 TextBuffState textHandler() throw(VmeException &) ;
00260
00261
00262
00263
00264
00265
00266 void getTextBuffer(char * buffer, long & length, TEXT_BUFFER_TYPE & type)
00267 throw();
00268
00269
00270
00271 void clearTextBuffer() throw();
00272
00273
00274 inline unsigned long readRodStatusReg(long regNumber) {
00275 unsigned long regValue;
00276 regValue = mdspSingleRead(STATUS_REG[regNumber]);
00277 return regValue;
00278 };
00279
00280
00281 inline unsigned long readRodCommandReg(long regNumber) {
00282 unsigned long regValue;
00283 regValue = mdspSingleRead(COMMAND_REG[regNumber]);
00284 return regValue;
00285 };
00286
00287
00288 inline bool readRodStatusBit(long regNumber, long bitNumber) {
00289 unsigned long rodStatusReg;
00290 rodStatusReg = readRodStatusReg(regNumber);
00291 return (0x1) & (readRodStatusReg(regNumber)>>bitNumber);
00292 };
00293
00294
00295 inline void setVmeCommandRegBit(const long bitNumber) {
00296 setBit(&m_vmeCommandReg[0], bitNumber);
00297 mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00298 return;
00299 };
00300
00301
00302 inline void clearVmeCommandRegBit(const long bitNumber) {
00303 clearBit(&m_vmeCommandReg[0], bitNumber);
00304 mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00305 return;
00306 };
00307
00308
00309
00310
00311
00312 void hpiLoad(const unsigned long hpiReg, const unsigned long hpiValue)
00313 throw(VmeException &);
00314
00315
00316
00317
00318
00319 unsigned long hpiFetch(const unsigned long hpiReg) throw(VmeException &);
00320
00321
00322
00323
00324 unsigned long mdspSingleRead(const unsigned long dspAddr) throw(VmeException &);
00325
00326
00327
00328
00329 void mdspSingleWrite(unsigned long dspAddr, unsigned long buffer)
00330 throw(VmeException &);
00331
00332
00333
00334
00335
00336
00337 void mdspBlockRead(const unsigned long dspAddr, unsigned long *buffer,
00338 long wordCount, HpidMode mode=DYNAMIC)
00339 throw (HpiException &, VmeException &);
00340
00341
00342
00343
00344
00345
00346 void mdspBlockWrite(const unsigned long dspAddr, unsigned long *buffer,
00347 long wordCount, HpidMode mode=DYNAMIC)
00348 throw (HpiException &, VmeException &);
00349
00350
00351
00352
00353 void mdspBlockDump(const unsigned long firstAddress,
00354 const unsigned long lastAddress, const std::string & fileName)
00355 throw(RodException &, VmeException &);
00356
00357
00358
00359
00360 void slvHpiLoad(unsigned long hpiReg, unsigned long hpiValue,
00361 long slaveNum) throw(VmeException &);
00362
00363
00364
00365
00366 unsigned long slvHpiFetch(unsigned long hpiReg, long slaveNum)
00367 throw(VmeException &);
00368
00369
00370
00371
00372 unsigned long slvSingleRead(unsigned long dspAddr, long slaveNum )
00373 throw(VmeException &);
00374
00375
00376
00377
00378
00379 void slvSingleWrite(unsigned long dspAddr, unsigned long buffer,
00380 long slaveNum) throw(VmeException &);
00381
00382
00383
00384
00385
00386
00387 void slvBlockRead(const unsigned long dspAddr, unsigned long buffer[],
00388 const long wordCount, long slaveNum, HpidMode mode=DYNAMIC)
00389 throw (HpiException &, VmeException &);
00390
00391
00392
00393
00394
00395
00396 void slvBlockWrite(unsigned long dspAddr, unsigned long buffer[],
00397 const long wordCount, long slaveNum, HpidMode mode=DYNAMIC)
00398 throw (HpiException &, VmeException &);
00399
00400
00401
00402 void resetMasterDsp() throw(VmeException &);
00403
00404
00405
00406 void resetSlaveDsp(long slaveNumber) throw(VmeException &);
00407
00408
00409
00410 void resetAllDsps() throw(VmeException &);
00411
00412
00413
00414 void chipEraseHpi() throw(VmeException &);
00415
00416
00417
00418 void sectorErase(unsigned long sectorBaseAddress)
00419 throw(RodException &, VmeException &) ;
00420
00421
00422
00423 void writeByteToFlash(unsigned long address, UINT8 data)
00424 throw (RodException &, VmeException &);
00425
00426
00427
00428 void writeBlockToFlash(unsigned long address, UINT8 *data,
00429 unsigned long numBytes) throw(VmeException &);
00430
00431
00432
00433 void writeBlockToFlashHpi(unsigned long address, UINT8 *data, unsigned long numBytes)
00434 throw (RodException &, VmeException &);
00435
00436
00437
00438 UINT8 readByteFromFlash(unsigned long address, long updateAddress)
00439 throw (RodException &, VmeException &);
00440
00441
00442
00443 void vmeWriteElementFlash(UINT8 value, unsigned long address,
00444 long handshakeBit) throw (RodException &, VmeException &);
00445
00446
00447
00448 void readBlockFromFlash(unsigned long address, UINT8 *buffer, unsigned long
00449 numBytes) throw(VmeException &) ;
00450
00451
00452
00453 void commonEraseCommands(unsigned long flashBaseAddr) throw(VmeException &);
00454
00455
00456
00457
00458 void commonEraseCommandsHpi(unsigned long flashBaseAddr) throw(VmeException &);
00459
00460
00461
00462 void sleep(const double milliSecs);
00463
00464
00465
00466 unsigned long checkSum(const unsigned long *sourceArray, const long wordCount);
00467
00468
00469
00470 unsigned long endianReverse32(const unsigned long inVal);
00471
00472
00473 private:
00474
00475 inline void setBit(unsigned long *var, long bitNumber) {
00476 *var = *var | (1<<bitNumber);
00477 return;
00478 }
00479
00480 inline void clearBit(unsigned long *var, long bitNumber) {
00481 *var&=(~(1<<bitNumber));
00482 return;
00483 }
00484
00485 inline bool readBit(unsigned long var, long bitNumber)
00486 {return ((var>>bitNumber)&1);}
00487
00488
00489 long m_slot;
00490
00491
00492 unsigned long m_serialNumber;
00493
00494
00495 VmePort* m_myVmePort;
00496
00497
00498 long m_numSlaves;
00499
00500
00501 long m_finBufferSize;
00502
00503
00504 std::string m_masterImageName;
00505
00506
00507 std::string m_slaveEmifName[4];
00508
00509
00510 std::string m_slaveIpramName[4];
00511
00512
00513 std::string m_slaveIdramName[4];
00514
00515
00516 std::string m_slaveExtName[4];
00517
00518
00519 unsigned long m_vmeCommandReg[2];
00520 unsigned long m_rodStatusReg[3];
00521
00522
00523 RodOutList* m_myOutList;
00524
00525
00526 PrimState m_myPrimState;
00527
00528
00529 TextBuffState m_myTextState;
00530
00531
00532 TEXT_BUFFER_TYPE m_textType;
00533
00534
00535 struct TXTBUFFER m_txtBuffer;
00536
00537
00538 char m_textData[TEXT_BUFF_SIZE];
00539
00540
00541 unsigned long* m_textBuff[N_TXT_BUFFS];
00542
00543 };
00544
00545 };
00546
00547
00548
00549
00550 ostream& std::operator<<(ostream& os, SctPixelRod::RodModule& rod);
00551
00552 #endif // SCTPIXELROD_RODMODULE_H
00553