Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

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 
00017 #if USE_THREADS
00018 enum RodPrimState { MYPRIM_STATE_LOADED, MYPRIM_STATE_EXECUTING, MYPRIM_STATE_COMPLETE, MYPRIM_STATE_IDLE };
00019 #endif
00020 
00021 namespace SctPixelRod {
00022   class RodOutList;
00023   class RodModule;
00024   class TimModule;
00025   class VmeInterface;
00026 }
00027 
00028 namespace SctApi {
00029   class PrimListWrapper;
00030 
00031   struct RodStatus {
00032 #if USE_THREADS
00033     std::list<boost::shared_ptr<PrimListWrapper> > listQueue;
00034     boost::mutex mutex;
00035     RodPrimState currState;
00036 #endif
00037     int slaves;
00038 
00039     std::map<BankType, std::vector<SctConfiguration::BOCChannelConfig> > savedBocSetup;
00040     std::map<BankType, boost::shared_ptr<SctConfiguration::BOCGlobalConfig> > savedBocRegisters;
00041   };
00042 
00052 class CrateImpl : public Crate {
00053   // Don't use copy constructor or assignment operator
00054   CrateImpl(const CrateImpl&);
00055   CrateImpl &operator=(const CrateImpl&);
00056  public:
00058 
00062   CrateImpl(unsigned int partition, unsigned int crate, 
00063             boost::shared_ptr<SctConfiguration::Configuration> newConf = boost::shared_ptr<SctConfiguration::Configuration>() );
00065 
00068   ~CrateImpl();
00069 
00070   /************** Interaction with Configuration **************/
00071 
00073 
00076   int initialiseCrate();
00077 
00079 
00082   int initialiseTim();
00083 
00085 
00089   int initialiseRod(unsigned int rod);
00090 
00092 
00095   int initialiseBOC(unsigned int rod);
00096 
00098 
00101   int configureBOC(unsigned int rod);
00102 
00103   /*************** Primlists *********************/
00104 
00106 
00109   int sendPrimList(unsigned int rod, boost::shared_ptr<PrimListWrapper> prim);
00110 
00112 
00115   int sendPrimListAll(boost::shared_ptr<PrimListWrapper> prim);
00116 
00118 
00124   int awaitResponse(unsigned int rod, int timeout);
00125 
00127 
00132   int awaitResponseAll(int timeout);
00133 
00135 
00138   boost::shared_ptr<SctPixelRod::RodOutList> getResponse(unsigned int rod);
00139 
00140   void setMrsStream(MRSStream *stream);
00141 
00142   /***************** Messages ******************/
00143 
00145 
00152   bool getRodMessage(unsigned int rod, char *buffer, unsigned long &length);
00153 
00154   /************** Misc read/writes *****************/
00155 
00157 
00160   int mdspBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords);
00161 
00163 
00166   int slvBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords, long slaveNumber);
00167 
00169 
00172   int slvBlockWrite(unsigned int rod, long dspStart, unsigned long* buffer, unsigned long numWords, long dspNumber);
00173 
00175 
00178   int mdspBlockWrite(unsigned int rod, long dspStart, unsigned long *buffer, unsigned long numWords);
00179 
00181 
00184   unsigned long readRodStatusReg(unsigned int rod, long regNumber);
00185 
00186 
00188 
00191   unsigned long readRodCommandReg(unsigned int rod, long regNumber);
00192 
00194 
00197   unsigned long dspSingleRead(unsigned int rod, const unsigned long dspAddr, long dspNumber);
00198 
00200 
00203   int dspSingleWrite(unsigned int rod, unsigned long dspAddr, unsigned long buffer, long dspNumber);
00204 
00206   void status();
00207 
00209   void primListControl(unsigned int rod, PLControl function);
00210 
00212   void printBOCSetup(unsigned int rod);
00213 
00215   std::vector<SctConfiguration::BOCChannelConfig> currentBOCSetup(unsigned int rod);
00216 
00218   void printBOCRegisters(unsigned int rod);
00219 
00221   SctConfiguration::BOCGlobalConfig currentBOCRegisters(unsigned int rod);
00222 
00224   void saveBOCSetup(unsigned int rod, BankType bank);
00225 
00227   void saveBOCRegisters(unsigned int rod, BankType bank);
00228 
00230   void restoreBOCSetup(unsigned int rod, BankType bank);
00231 
00233   void restoreBOCRegisters(unsigned int rod, BankType bank);
00234 
00236   bool checkBOCLasersOn(unsigned int rod);
00237 
00239   void enterBOCClockBy2Mode(unsigned int rod);
00240 
00242   void leaveBOCClockBy2Mode(unsigned int rod);
00243 
00245   std::vector<double> getBOCMonitorArray(unsigned int rod);
00246 
00248 
00251   void modifyBOCParam(unsigned int type, unsigned int val, bool raw);
00252 
00254   void modifyBOCParam(unsigned int rod, unsigned int channel, unsigned int type, unsigned int val, bool raw);
00255 
00257   void lasersOff();
00258 
00259   /* ******************* TIM Functions ***************************/
00260 
00262 
00266   void timSetFrequency(double trigFreq, double rstFreq);
00267 
00269   void freeTriggers();
00270 
00272   void stopTriggers();
00273 
00275   void timL1A();
00276 
00278   void timCalL1A(int delay);
00279 
00280   void timECR();
00281 
00282   void timBCR();
00283 
00284   void timFER();
00285 
00287   void sendTimBurst(int count);
00288 
00290   void timVerbose();
00291 
00293   void timRegLoad(int reg, UINT16 val);
00294 
00296   UINT16 timRegRead(int reg);
00297 
00299   bool slavePresent(int rod, int index) const;
00300 
00302   void slaveStarted(int rod, int slave);
00303 
00305   bool RODPresent(int rod) const;
00306   
00308   std::list<unsigned> getListOfRods() const;
00309 
00310   long getRodSlot(int rod) const;
00311 
00313   int getRodRevision(int rod) const;
00314 
00316   void stopPolling();
00317 
00319   void resumePolling();
00320 
00321  private:
00322   void rodInitialiseThread(int rod);
00323 
00325   void setupScanTx(unsigned int rod, unsigned int channel);
00326 
00328   void setupScanRawTx(unsigned int rod, unsigned int channel);
00329 
00331 
00334   SctPixelRod::RodModule *getRod(unsigned int rod) const;
00335 
00336   const RodStatus &getRodData(unsigned int rod) const;
00337   RodStatus &getRodData(unsigned int rod);
00338 
00340   void doTextBuffer(SctPixelRod::RodModule &rod0);
00341 
00342 #if USE_THREADS
00343   void pollingLoop();
00344 #endif
00345 
00347   typedef std::map<unsigned int, std::pair<RodStatus *, SctPixelRod::RodModule *> > RodMap;
00348 
00350   RodMap rodMap;
00351 
00353   SctPixelRod::TimModule *tim;
00354 
00356   boost::shared_ptr<SctConfiguration::Configuration> config;
00357 
00359   SctPixelRod::VmeInterface *vme;
00360 
00362   const unsigned int partition;
00363 
00365   const unsigned int crate;
00366 
00367   MRSStream *mrs;
00368 
00369   // Leave this in for no threads (its nice and small...)
00370   bool m_stopPolling;
00371 
00372   // Whether polling should be done
00373   bool m_enablePolling;
00374 
00375 #if USE_THREADS
00376 
00377   std::list<boost::shared_ptr<PrimListWrapper> > listQueueAll;
00378 
00379   /* **********  Mutexes  ********** */
00380   boost::mutex vmeMutex;
00381 
00382   boost::condition primQueue_notEmpty;
00383   boost::mutex primQueue_mutex;
00384 
00385   /* ******* Threads ******/
00386   std::auto_ptr<boost::thread> pollThread;
00387 
00388   // So ROD initialisation threads can count RODs independently
00389   int rodCounter;
00390 #endif
00391 };
00392 
00393 }  // End of namespace SctApi
00394 #endif

Generated on Fri Sep 16 18:01:50 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5