00001 #ifndef SCTAPI_CRATE
00002 #define SCTAPI_CRATE
00003
00004 #include <list>
00005 #include <map>
00006 #include <memory>
00007 #include <mrs/message.h>
00008
00009 #include <boost/thread.hpp>
00010 #include <boost/shared_ptr.hpp>
00011
00012 #include "primListWrapper.h"
00013
00014 #include "RodCrate/TimModule.h"
00015 #if USE_THREADS
00016 enum RodPrimState { MYPRIM_LOADED, MYPRIM_EXECUTING, MYPRIM_COMPLETE, MYPRIM_IDLE };
00017 #endif
00018
00019 using boost::shared_ptr;
00020
00021 namespace SctPixelRod {
00022 class RodOutList;
00023 class RodModule;
00024
00025 }
00026
00027 class VmeInterface;
00028
00029 namespace SctConfiguration {
00030 class Configuration;
00031 }
00032
00033 namespace SctApi {
00034 struct RodStatus {
00035 #if USE_THREADS
00036 std::list<boost::shared_ptr<PrimListWrapper> > listQueue;
00037 boost::mutex mutex;
00038 RodPrimState currState;
00039 #endif
00040 int slaves;
00041 };
00042
00052 class Crate {
00053
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
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
00098
00100
00103 int sendPrimList(unsigned int rod, shared_ptr<PrimListWrapper> prim);
00104
00106
00109 int sendPrimListAll(shared_ptr<PrimListWrapper> 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
00137
00139
00146 bool getRodMessage(unsigned int rod, char *buffer, int &length);
00147
00148
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
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
00257 bool RODPresent(int rod) const;
00258
00259 private:
00261
00264 SctPixelRod::RodModule *getRod(unsigned int rod) const;
00265
00266 const RodStatus &getRodData(unsigned int rod) const;
00267 RodStatus &getRodData(unsigned int rod);
00268
00270 void doTextBuffer(SctPixelRod::RodModule &rod0);
00271
00272 #if USE_THREADS
00273 void pollingLoop();
00274 #endif
00275
00277 typedef std::map<unsigned int, std::pair<RodStatus *, SctPixelRod::RodModule *> > RodMap;
00278
00280 RodMap rodMap;
00281
00283 SctPixelRod::TimModule *tim;
00284
00286 boost::shared_ptr<SctConfiguration::Configuration> config;
00287
00289 SctPixelRod::VmeInterface *vme;
00290
00292 const unsigned int partition;
00293
00295 const unsigned int crate;
00296
00297 MRSStream *mrs;
00298
00299
00300 bool stopPolling;
00301
00302 #if USE_THREADS
00303
00304 std::list<shared_ptr<PrimListWrapper> > listQueueAll;
00305
00306
00307 boost::mutex vmeMutex;
00308
00309
00310 std::auto_ptr<boost::thread> pollThread;
00311 #endif
00312 };
00313
00314 }
00315 #endif