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

crate.h

00001 #ifndef SCTAPI_CRATE
00002 #define SCTAPI_CRATE
00003 
00004 #include <list>
00005 #include <map>
00006 #include <mrs/message.h>
00007 
00008 #include <boost/thread.hpp>
00009 #include <boost/shared_ptr.hpp>
00010 
00011 #include "RodCrate/TimModule.h"              // For TimMaskFrequency
00012 #if USE_THREADS
00013 enum RodPrimState { MYPRIM_LOADED, MYPRIM_EXECUTING, MYPRIM_COMPLETE, MYPRIM_IDLE };
00014 #endif
00015 
00016 using boost::shared_ptr;
00017 
00018 namespace SctPixelRod {
00019   class RodOutList;
00020   class RodPrimList;
00021   class RodModule;
00022   class TimModule;
00023 }
00024 
00025 class VmeInterface;
00026 
00027 namespace SctConfiguration {
00028   class Configuration;
00029 }
00030 
00031 namespace {
00032   struct RodStatus {
00033 #if USE_THREADS
00034     std::list<SctPixelRod::RodPrimList*> listQueue;
00035     boost::mutex mutex;
00036     RodPrimState currState;
00037 #endif
00038     int slaves;
00039   };
00040 }
00041 
00042 namespace SctApi {
00052 class Crate {
00053   // Don't use copy constructor or assignment operator
00054   Crate(const Crate&);
00055   Crate &operator=(const Crate&);
00056  public:
00058 
00062   Crate(unsigned int partition, unsigned int crate, 
00063         boost::shared_ptr<SctConfiguration::Configuration> newConf = boost::shared_ptr<SctConfiguration::Configuration>() );
00065 
00068   ~Crate();
00069 
00070   /************** Interaction with Configuration **************/
00071 
00073 
00076   int initialiseTim();
00077 
00079 
00083   int initialiseRod(unsigned int rod);
00084 
00086 
00089   int initialiseBOC(unsigned int rod);
00090 
00092 
00095   int configureBOC(unsigned int rod);
00096 
00097   /*************** Primlists *********************/
00098 
00100 
00103   int sendPrimList(unsigned int rod, SctPixelRod::RodPrimList *prim);
00104 
00106 
00109   int sendPrimListAll(SctPixelRod::RodPrimList *prim);
00110 
00112 
00118   int awaitResponse(unsigned int rod, int timeout);
00119 
00121 
00126   int awaitResponseAll(int timeout);
00127 
00129 
00132   shared_ptr<SctPixelRod::RodOutList> getResponse(unsigned int rod);
00133 
00134   void setMrsStream(MRSStream *stream);
00135 
00136   /***************** Messages ******************/
00137 
00139 
00146   bool getRodMessage(unsigned int rod, char *buffer, int &length);
00147 
00148   /************** Misc read/writes *****************/
00149 
00151 
00154   int mdspBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, long numWords);
00155 
00157 
00160   int slvBlockRead(unsigned int rod, long dspStart, unsigned long *buffer, long numWords, long slaveNumber);
00161 
00163 
00166   int slvBlockWrite(unsigned int rod, long dspStart, unsigned long* buffer, long numWords, long dspNumber);
00167 
00169 
00172   int mdspBlockWrite(const unsigned int rod, const long dspStart, unsigned long *buffer, const long numWords);
00173 
00175 
00178   unsigned long readRodStatusReg(unsigned int rod, long regNumber);
00179 
00180 
00182 
00185   unsigned long readRodCommandReg(unsigned int rod, long regNumber);
00186 
00188 
00191   unsigned long dspSingleRead(unsigned int rod, const unsigned long dspAddr, long dspNumber);
00192 
00194 
00197   int dspSingleWrite(unsigned int rod, unsigned long dspAddr, unsigned long buffer, long dspNumber);
00198 
00200   void status();
00201 
00203 
00209   enum PLControl {
00210     C_PL_STOP,
00211     C_PL_PAUSE,
00212     C_PL_RESUME,
00213     C_PL_CANCEL };
00214 
00216   void primListControl(unsigned int rod, PLControl function);
00217 
00219   void printBOCSetup(unsigned int rod);
00220 
00222   void printBOCRegisters(unsigned int rod);
00223 
00225   bool checkBOCLasersOn(unsigned int rod);
00226 
00228   void enterBOCClockBy2Mode(unsigned int rod);
00229 
00231   void leaveBOCClockBy2Mode(unsigned int rod);
00232 
00234   void modifyBOCParam(unsigned int rod, unsigned int channel, unsigned int type, unsigned int val);
00235 
00237   void lasersOff();
00238 
00239   /* ******************* TIM Functions ***************************/
00240 
00242   void freeTriggers(SctPixelRod::TimMaskFrequency freq = SctPixelRod::TIM_MASK_TRIG_10_0KHZ);
00243 
00245   void stopTriggers();
00246 
00248   void timL1A();
00249 
00251   void timCalL1A(int delay);
00252 
00254   bool slavePresent(int rod, int index) const;
00255 
00256  private:
00258 
00261   SctPixelRod::RodModule *getRod(unsigned int rod) const;
00262 
00263   const RodStatus &getRodData(unsigned int rod) const;
00264   RodStatus &getRodData(unsigned int rod);
00265 
00267   void doTextBuffer(SctPixelRod::RodModule &rod0);
00268 
00269 #if USE_THREADS
00270   void pollingLoop();
00271 #endif
00272 
00274   typedef std::map<unsigned int, std::pair<RodStatus *, SctPixelRod::RodModule *> > RodMap;
00275 
00277   RodMap rodMap;
00278 
00280   SctPixelRod::TimModule *tim;
00281 
00283   boost::shared_ptr<SctConfiguration::Configuration> config;
00284 
00286   SctPixelRod::VmeInterface *vme;
00287 
00289   const unsigned int partition;
00290 
00292   const unsigned int crate;
00293 
00294   MRSStream *mrs;
00295 
00296   // Leave this in for no threads (its nice and small...)
00297   bool stopPolling;
00298 
00299 #if USE_THREADS
00300 
00301   std::list<SctPixelRod::RodPrimList*> listQueueAll;
00302 
00303   /* **********  Mutexes  ********** */
00304   boost::mutex vmeMutex;
00305 
00306   /* ******* Threads ******/
00307   std::auto_ptr<boost::thread> pollThread;
00308 #endif
00309 };
00310 }  // End of namespace SctApi
00311 #endif

Generated on Tue Dec 9 10:07:35 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3