crateImpl.h

00001 #ifndef SCTAPI_CRATE_IMPL
00002 #define SCTAPI_CRATE_IMPL
00003 
00004 // Make sure all compilations have same Crate structure!
00005 #include "config.h"
00006 
00007 #include <list>
00008 #include <map>
00009 #include <memory>
00010 #include <mrs/message.h>
00011 
00012 #include <boost/thread.hpp>
00013 #include <boost/shared_ptr.hpp>
00014 
00015 #include "crate.h"
00016 #include "Sct/Addressing.h"
00017 
00018 #if USE_THREADS
00019 enum RodPrimState { MYPRIM_STATE_LOADED, MYPRIM_STATE_EXECUTING, MYPRIM_STATE_COMPLETE, MYPRIM_STATE_IDLE };
00020 #endif
00021 
00022 namespace SctPixelRod {
00023   class RodOutList;
00024   class RodModule;
00025   class TimModule;
00026   class VmeInterface;
00027 }
00028 
00029 namespace SctApi {
00030   class PrimListWrapper;
00031 
00032   struct RodStatus {
00033 #if USE_THREADS
00034     std::list<boost::shared_ptr<PrimListWrapper> > listQueue;
00035     boost::mutex mutex;
00036     RodPrimState currState;
00037 #endif
00038     int slaves;
00039 
00040     std::map<BankType, std::vector<SctConfiguration::BOCChannelConfig> > savedBocSetup;
00041     std::map<BankType, boost::shared_ptr<SctConfiguration::BOCGlobalConfig> > savedBocRegisters;
00042   };
00043 
00053 class CrateImpl : public Crate {
00054   // Don't use copy constructor or assignment operator
00055   CrateImpl(const CrateImpl&);
00056   CrateImpl &operator=(const CrateImpl&);
00057  public:
00059 
00063   CrateImpl(const Sct::UCID & ucid, 
00064             boost::shared_ptr<SctConfiguration::Configuration> newConf = boost::shared_ptr<SctConfiguration::Configuration>() );
00066 
00069   ~CrateImpl();
00070 
00071   /************** Interaction with Configuration **************/
00072 
00074 
00077   int initialiseCrate();
00078 
00080 
00083   int initialiseTim();
00084 
00086 
00090   int initialiseRod(unsigned int rod);
00091 
00093 
00096   int initialiseBOC(unsigned int rod);
00097 
00099 
00102   int configureBOC(unsigned int rod);
00103   
00105 
00109   SctPixelRod::RodModule *getRod(unsigned int rod) const;
00110 
00111   /*************** Primlists *********************/
00112 
00114 
00117   int sendPrimList(unsigned int rod, boost::shared_ptr<PrimListWrapper> prim);
00118 
00120 
00123   int sendPrimListAll(boost::shared_ptr<PrimListWrapper> prim);
00124 
00126 
00132   int awaitResponse(unsigned int rod, int timeout);
00133 
00135 
00140   int awaitResponseAll(int timeout);
00141 
00143 
00146   boost::shared_ptr<SctPixelRod::RodOutList> getResponse(unsigned int rod);
00147 
00148   void setMrsStream(MRSStream *stream);
00149 
00150   /***************** Messages ******************/
00151 
00153 
00160   bool getRodMessage(unsigned int rod, char *buffer, unsigned long &length);
00161 
00162   /************** Misc read/writes *****************/
00163 
00165 
00168   int mdspBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords);
00169 
00171 
00174   int slvBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords, long slaveNumber);
00175 
00177 
00180   int slvBlockWrite(unsigned int rod, long dspStart, unsigned long* buffer, unsigned long numWords, long dspNumber);
00181 
00183 
00186   int mdspBlockWrite(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords);
00187 
00189 
00192   unsigned long readRodStatusReg(unsigned int rod, long regNumber);
00193 
00194 
00196 
00199   unsigned long readRodCommandReg(unsigned int rod, long regNumber);
00200 
00202 
00205   unsigned long dspSingleRead(unsigned int rod, const unsigned long dspAddr, long dspNumber);
00206 
00208 
00211   int dspSingleWrite(unsigned int rod, unsigned long dspAddr, unsigned long buffer, long dspNumber);
00212 
00214   std::string status();
00215 
00217   void primListControl(unsigned int rod, PLControl function);
00218 
00220   void printBOCSetup(unsigned int rod);
00221 
00223   std::vector<SctConfiguration::BOCChannelConfig> currentBOCSetup(unsigned int rod);
00224 
00226   void printBOCRegisters(unsigned int rod);
00227 
00229   SctConfiguration::BOCGlobalConfig currentBOCRegisters(unsigned int rod);
00230 
00232   void saveBOCSetup(unsigned int rod, BankType bank);
00233 
00235   void saveBOCRegisters(unsigned int rod, BankType bank);
00236 
00238   void restoreBOCSetup(unsigned int rod, BankType bank);
00239 
00241   void restoreBOCRegisters(unsigned int rod, BankType bank);
00242 
00244   bool checkBOCLasersOn(unsigned int rod);
00245 
00247   void enterBOCClockBy2Mode(unsigned int rod);
00248 
00250   void leaveBOCClockBy2Mode(unsigned int rod);
00251 
00253   std::vector<double> getBOCMonitorArray(unsigned int rod);
00254 
00256   virtual void modifyTIMParam(unsigned int type, unsigned int val);
00257 
00259 
00262   void modifyBOCParam(unsigned int type, unsigned int val, bool raw);
00263 
00265   void modifyBOCParam(unsigned int rod, unsigned int channel, unsigned int type, unsigned int val, bool raw);
00266 
00268   void lasersOff();
00269 
00270   /* ******************* TIM Functions ***************************/
00271 
00273 
00277   void timSetFrequency(double trigFreq, double rstFreq);
00278 
00280   virtual double timGetTriggerFrequency();
00281 
00283   virtual double timGetResetFrequency();
00284 
00286   virtual void timLoadSequence(const std::vector<unsigned>& seq);
00287 
00294   virtual unsigned long timRunSequence(long unsigned ntrigs, int random, bool external);
00295 
00297   void freeTriggers();
00298 
00300   void stopTriggers();
00301 
00303   void timL1A();
00304 
00306   void timCalL1A(int delay);
00307 
00308   void timECR();
00309 
00310   void timBCR();
00311 
00312   void timFER();
00313 
00315   unsigned long sendTimBurst(unsigned long count, int random, bool external);
00316 
00318   void timVerbose();
00319 
00321   void timRegLoad(int reg, UINT16 val);
00322 
00324   UINT16 timRegRead(int reg);
00325 
00327   bool slavePresent(int rod, int index) const;
00328 
00330   void slaveStarted(int rod, int slave);
00331 
00333   bool RODPresent(int rod) const;
00334   
00336   std::list<unsigned> getListOfRods() const;
00337 
00338   long getRodSlot(int rod) const;
00339 
00341   int getRodRevision(int rod) const;
00342 
00344   void stopPolling();
00345 
00347   void resumePolling();
00348 
00349  private:
00350   void rodInitialiseThread(int rod);
00351 
00353   void setupScanTx(unsigned int rod, unsigned int channel);
00354 
00356   void setupScanRawTx(unsigned int rod, unsigned int channel);
00357 
00358   const RodStatus &getRodData(unsigned int rod) const;
00359   RodStatus &getRodData(unsigned int rod);
00360 
00362   void doTextBuffer(SctPixelRod::RodModule &rod0);
00363 
00364 #if USE_THREADS
00365   void pollingLoop();
00366 #endif
00367 
00369   typedef std::map<unsigned int, std::pair<RodStatus *, SctPixelRod::RodModule *> > RodMap;
00370 
00372   RodMap rodMap;
00373 
00375   SctPixelRod::TimModule *tim;
00376 
00378   boost::shared_ptr<SctConfiguration::Configuration> config;
00379 
00381   SctPixelRod::VmeInterface *vme;
00382 
00383   MRSStream *mrs;
00384 
00385   // Leave this in for no threads (its nice and small...)
00386   bool m_stopPolling;
00387 
00388   // Whether polling should be done
00389   bool m_enablePolling;
00390 
00391 #if USE_THREADS
00392 
00393   std::list<boost::shared_ptr<PrimListWrapper> > listQueueAll;
00394 
00395   /* **********  Mutexes  ********** */
00396   boost::mutex vmeMutex;
00397 
00398   boost::condition primQueue_notEmpty;
00399   boost::mutex primQueue_mutex;
00400 
00401   /* ******* Threads ******/
00402   std::auto_ptr<boost::thread> pollThread;
00403 
00404   // So ROD initialisation threads can count RODs independently
00405   int rodCounter;
00406 #endif
00407 };
00408 
00409 }  // End of namespace SctApi
00410 #endif

Generated on Mon Feb 6 14:01:18 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6