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 "BaseException.h"
00013 #include "RodPrimitive.h"
00014 #include "RodPrimList.h"
00015 #include "VmeInterface.h"
00016 #include "VmePort.h"
00017 #include "VmeModule.h"
00018 #include "processor.h"
00019 #include "RodRegisterBits.h"
00020 #include "smSendTxtBuff.h"
00021 #include "RodDspAddresses.h"
00022 #include "RodVmeAddresses.h"
00023 #include "RodOutList.h"
00024 #include "txtBuffer.h"
00025
00026 namespace SctPixelRod {
00027
00028
00029 class BocCard;
00030
00031 enum TextBuffState {TEXT_IDLE, TEXT_RQ_SET, TEXT_READOUT, TEXT_ERROR};
00032 enum PrimState {PRIM_IDLE, PRIM_LOADED, PRIM_EXECUTING, PRIM_WAITING, PRIM_PAUSED};
00033 enum TEXT_BUFFER_TYPE {TEXT_ERR, TEXT_INFO, TEXT_DIAG, TEXT_XFER, TEXT_UNDEF};
00034 enum HpidMode {DYNAMIC, AUTO, NO_AUTO};
00035
00036
00037
00049 class NoImageFile : public BaseException {
00050 public:
00051 NoImageFile( std::string descriptor, std::string fileName);
00052 std::string getFileName() {return m_fileName;};
00053 virtual void what(std::ostream&);
00054
00055 private:
00056 std::string m_fileName;
00057 };
00058
00059
00060
00071 class HpiException : public BaseException {
00072 public:
00073 HpiException( std::string descriptor, unsigned long calcAddr, unsigned long readAddr);
00074 unsigned long getCalcAddr() {return m_calcAddr;};
00075 unsigned long getReadAddr() {return m_readAddr;};
00076 virtual void what(std::ostream&);
00077
00078 private:
00079 unsigned long m_calcAddr;
00080 unsigned long m_readAddr;
00081 };
00082
00083
00084
00095 class RodException : public BaseException {
00096 public:
00097 RodException( std::string descriptor);
00098 RodException( std::string descriptor, unsigned long data1);
00099 RodException( std::string descriptor, unsigned long data1, unsigned long data2);
00100 unsigned long getData1() {return m_data1;};
00101 unsigned long getData2() {return m_data2;};
00102 unsigned long getNumData() {return m_numData;};
00103 virtual void what(std::ostream&);
00104
00105 private:
00106 unsigned long m_numData;
00107 unsigned long m_data1;
00108 unsigned long m_data2;
00109 };
00110
00111
00113
00114 *
00115 * @brief This is a derived class providing the software interface for VME ROD modules.
00116 *
00117 * This is the implementation of a ROD class derived from the VmeModules base class
00118 * It should be the sole interface for VME communication with the ROD modules.
00119 *
00120 * @author Tom Meyer (meyer@iastate.edu) - originator
00121 */
00122
00123 class RodModule : public VmeModule {
00124 RodModule(const RodModule& rhs);
00125 RodModule &operator=(const RodModule & rhs);
00126
00127 public:
00128
00129
00130 RodModule( unsigned long baseAddr, unsigned long mapSize, VmeInterface & ourInterface,
00131 long numSlaves) throw (RodException&, VmeException &);
00132 virtual ~RodModule();
00133
00134
00135
00136 unsigned long getBaseAddress() {return m_baseAddress; }
00137 long getSlot() const { return m_slot; }
00138 unsigned long getSerialNumber() {return m_serialNumber;};
00139 unsigned long getRevision() {return m_revision;};
00140 void setNumSlaves( long numSlaves) { m_numSlaves = numSlaves; }
00141 long getNumSlaves() const { return m_numSlaves; }
00142 void setFinBufferSize( long finBufferSize) { m_finBufferSize = finBufferSize;}
00143 long getFinBufferSize() const { return m_finBufferSize; }
00144 std::string getMasterImageName() {return m_masterImageName; }
00145 std::string getslaveIpramName(long slaveNum) {return m_slaveIpramName[slaveNum];}
00146 std::string getslaveIdramName(long slaveNum) {return m_slaveIdramName[slaveNum];}
00147 std::string getslaveExtName(long slaveNum) {return m_slaveExtName[slaveNum];}
00148 unsigned long getVmeCommandRegVal(long regNum) {
00149 return m_vmeCommandReg[regNum];
00150 };
00151 VmePort* getVmePort() {return m_myVmePort; };
00152 BocCard* getBocCard() {return m_myBoc; }
00153 void setOutList(RodOutList* outList) {m_myOutList = outList;};
00154 RodOutList* getOutList() {return m_myOutList;};
00155 PrimState getPrimState() {return m_myPrimState;};
00156 TextBuffState getTextState() {return m_myTextState;};
00157
00158 long getMode() { return long(m_txtBuffer.mode);};
00159 long getOverwrite() {return long(m_txtBuffer.overwrite);};
00160 long getOverflow() {return long(m_txtBuffer.overflow);};
00161 long getWrap() {return long(m_txtBuffer.wrap);};
00162 TEXT_BUFFER_TYPE getTextBufferType() {return m_textType;};
00163
00177 void initialize();
00178 void initialize(bool resetFlag) throw (RodException &, VmeException &);
00179
00183 void reset() throw (RodException&, VmeException &);
00184
00189 void status() throw();
00190
00195 bool verify() throw();
00196
00204 void initSlaveDsp(const std::string & ipramFile,
00205 const std::string & idramFile,const std::string & extFile,
00206 const long slaveNumber, char opt='n') throw(RodException&, NoImageFile&, VmeException &);
00207
00212 void loadSlaveImage(const std::string & filename, const unsigned long address,
00213 const long slaveNumber, char opt='n')
00214 throw (NoImageFile &, RodException &, VmeException &);
00215
00219 void startSlave(const long slaveNumber, char mode='s') throw(VmeException &);
00220
00229 void synchSendPrim(RodPrimitive & prim) throw (RodException &, VmeException &) ;
00230
00242 void sendPrimList(RodPrimList *l) throw(VmeException &) ;
00243
00248 PrimState primHandler() throw (RodException &, VmeException &);
00249
00251 inline bool getDspAck() {return readRodStatusBit(0, DSPACK);};
00252
00254 inline void setInListReady(){setVmeCommandRegBit(INLISTRDY); return;};
00255
00257 void deleteOutList() throw() ;
00258
00262 inline long getAllTextBuffBits() {
00263 unsigned long regValue;
00264 regValue = readRodStatusReg(0);
00265 return (regValue>>TEXT_BUFF_NOT_EMPTY[0] & 0xF);
00266 };
00267
00273 TextBuffState textHandler() throw(VmeException &) ;
00274
00280 void getTextBuffer(char * buffer, long & length, TEXT_BUFFER_TYPE & type)
00281 throw();
00282
00285 void clearTextBuffer() throw();
00286
00288 inline unsigned long readRodStatusReg(long regNumber) {
00289 unsigned long regValue;
00290 regValue = mdspSingleRead(STATUS_REG[regNumber]);
00291 return regValue;
00292 };
00293
00295 inline unsigned long readRodCommandReg(long regNumber) {
00296 unsigned long regValue;
00297 regValue = mdspSingleRead(COMMAND_REG[regNumber]);
00298 return regValue;
00299 };
00300
00302 inline bool readRodStatusBit(long regNumber, long bitNumber) {
00303 unsigned long rodStatusReg;
00304 rodStatusReg = readRodStatusReg(regNumber);
00305 return (0x1) & (readRodStatusReg(regNumber)>>bitNumber);
00306 };
00307
00309 inline void setVmeCommandRegBit(const long bitNumber) {
00310 setBit(&m_vmeCommandReg[0], bitNumber);
00311 mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00312 return;
00313 };
00314
00316 inline void clearVmeCommandRegBit(const long bitNumber) {
00317 clearBit(&m_vmeCommandReg[0], bitNumber);
00318 mdspSingleWrite(COMMAND_REG[0], m_vmeCommandReg[0]);
00319 return;
00320 };
00321
00326 void hpiLoad(const unsigned long hpiReg, const unsigned long hpiValue)
00327 throw(VmeException &);
00328
00333 unsigned long hpiFetch(const unsigned long hpiReg) throw(VmeException &);
00334
00338 unsigned long mdspSingleRead(const unsigned long dspAddr) throw(VmeException &);
00339
00343 void mdspSingleWrite(unsigned long dspAddr, unsigned long buffer)
00344 throw(VmeException &);
00345
00351 void mdspBlockRead(const unsigned long dspAddr, unsigned long *buffer,
00352 long wordCount, HpidMode mode=DYNAMIC)
00353 throw (HpiException &, VmeException &);
00354
00360 void mdspBlockWrite(const unsigned long dspAddr, unsigned long *buffer,
00361 long wordCount, HpidMode mode=DYNAMIC)
00362 throw (HpiException &, VmeException &);
00363
00367 void mdspBlockDump(const unsigned long firstAddress,
00368 const unsigned long lastAddress, const std::string & fileName)
00369 throw(RodException &, VmeException &);
00370
00374 void slvHpiLoad(unsigned long hpiReg, unsigned long hpiValue,
00375 long slaveNum) throw(VmeException &);
00376
00380 unsigned long slvHpiFetch(unsigned long hpiReg, long slaveNum)
00381 throw(VmeException &);
00382
00386 unsigned long slvSingleRead(unsigned long dspAddr, long slaveNum )
00387 throw(VmeException &);
00388
00393 void slvSingleWrite(unsigned long dspAddr, unsigned long buffer,
00394 long slaveNum) throw(VmeException &);
00395
00401 void slvBlockRead(const unsigned long dspAddr, unsigned long buffer[],
00402 const long wordCount, long slaveNum, HpidMode mode=DYNAMIC)
00403 throw (HpiException &, VmeException &);
00404
00410 void slvBlockWrite(unsigned long dspAddr, unsigned long buffer[],
00411 const long wordCount, long slaveNum, HpidMode mode=DYNAMIC)
00412 throw (HpiException &, VmeException &);
00413
00416 void resetMasterDsp() throw(VmeException &);
00417
00420 void resetSlaveDsp(long slaveNumber) throw(VmeException &);
00421
00424 void resetAllDsps() throw(VmeException &);
00425
00428 void chipEraseHpi() throw(VmeException &);
00429
00432 void sectorErase(unsigned long sectorBaseAddress)
00433 throw(RodException &, VmeException &) ;
00434
00437 void writeByteToFlash(unsigned long address, UINT8 data)
00438 throw (RodException &, VmeException &);
00439
00442 void writeBlockToFlash(unsigned long address, UINT8 *data,
00443 unsigned long numBytes) throw(VmeException &);
00444
00447 void writeBlockToFlashHpi(unsigned long address, UINT8 *data, unsigned long numBytes)
00448 throw (RodException &, VmeException &);
00449
00452 UINT8 readByteFromFlash(unsigned long address, long updateAddress)
00453 throw (RodException &, VmeException &);
00454
00457 void vmeWriteElementFlash(UINT8 value, unsigned long address,
00458 long handshakeBit) throw (RodException &, VmeException &);
00459
00462 void readBlockFromFlash(unsigned long address, UINT8 *buffer, unsigned long
00463 numBytes) throw(VmeException &) ;
00464
00467 void commonEraseCommands(unsigned long flashBaseAddr) throw(VmeException &);
00468
00472 void commonEraseCommandsHpi(unsigned long flashBaseAddr) throw(VmeException &);
00473
00477 unsigned long getFlashSectorSize();
00478
00481 void sleep(const double milliSecs);
00482
00485 unsigned long checkSum(const unsigned long *sourceArray, const long wordCount);
00486
00489 unsigned long endianReverse32(const unsigned long inVal);
00490
00491
00492 private:
00494 inline void setBit(unsigned long *var, long bitNumber) {
00495 *var = *var | (1<<bitNumber);
00496 return;
00497 }
00498
00499 inline void clearBit(unsigned long *var, long bitNumber) {
00500 *var&=(~(1<<bitNumber));
00501 return;
00502 }
00503
00504 inline bool readBit(unsigned long var, long bitNumber)
00505 {return ((var>>bitNumber)&1);}
00506
00508 long m_slot;
00509
00511 unsigned long m_serialNumber;
00512
00514 unsigned long m_revision;
00515
00517 VmePort* m_myVmePort;
00518
00520 long m_numSlaves;
00521
00523 long m_finBufferSize;
00524
00526 std::string m_masterImageName;
00527
00529 std::string m_slaveIpramName[4];
00530
00532 std::string m_slaveIdramName[4];
00533
00535 std::string m_slaveExtName[4];
00536
00538 unsigned long m_vmeCommandReg[2];
00539 unsigned long m_rodStatusReg[3];
00540
00542 RodOutList* m_myOutList;
00543
00545 PrimState m_myPrimState;
00546
00548 TextBuffState m_myTextState;
00549
00551 TEXT_BUFFER_TYPE m_textType;
00552
00554 struct TXTBUFFER m_txtBuffer;
00555
00557 char m_textData[TEXT_BUFF_SIZE];
00558
00560 unsigned long* m_textBuff[N_TXT_BUFFS];
00561
00563 BocCard* m_myBoc;
00564
00565 };
00566
00567 };
00568
00569
00570
00571
00572
00573 std::ostream& operator<<(std::ostream& os, SctPixelRod::RodModule& rod);
00574
00575
00576
00577
00578 #endif // SCTPIXELROD_RODMODULE_H
00579