changes from fzhou
[u/mrichter/AliRoot.git] / TRD / AliTRDtrapConfig.h
1 #ifndef ALITRDTRAPCONFIG_H
2 #define ALITRDTRAPCONFIG_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 // Configuration of the TRD TRAcklet Processor
7 // (TRD Front-End Electronics)
8 //
9 // TRAP registers
10 // TRAP data memory (DMEM)
11
12 #include <TObject.h>
13 #include <TNamed.h>
14 #include <TString.h>
15 #include <fstream>
16 using std::ostream;
17
18 class AliTRDtrapConfig : public TNamed
19 {
20  public:
21   AliTRDtrapConfig(const TString &name = "", const TString &title = "");
22   ~AliTRDtrapConfig();
23
24   // allocation
25   enum Alloc_t {
26     kAllocNone,
27     kAllocGlobal,
28     kAllocByDetector,
29     kAllocByHC,
30     kAllocByMCM,
31     kAllocByMergerType,
32     kAllocByLayer,
33     kAllocByMCMinSM,
34     kAllocLast
35   }; // possible granularities for allocation
36      // common to registers and DMEM
37
38   // registers
39   enum TrapReg_t { kSML0,
40                   kSML1,
41                   kSML2,
42                   kSMMODE,
43                   kSMCMD,
44                   kNITM0,
45                   kNITM1,
46                   kNITM2,
47                   kNIP4D,
48                   kCPU0CLK,
49                   kCPU1CLK,
50                   kCPU2CLK,
51                   kCPU3CLK,
52                   kNICLK,
53                   kFILCLK,
54                   kPRECLK,
55                   kADCEN,
56                   kNIODE,
57                   kNIOCE,
58                   kNIIDE,
59                   kNIICE,
60                   kARBTIM,
61                   kIA0IRQ0,
62                   kIA0IRQ1,
63                   kIA0IRQ2,
64                   kIA0IRQ3,
65                   kIA0IRQ4,
66                   kIA0IRQ5,
67                   kIA0IRQ6,
68                   kIA0IRQ7,
69                   kIA0IRQ8,
70                   kIA0IRQ9,
71                   kIA0IRQA,
72                   kIA0IRQB,
73                   kIA0IRQC,
74                   kIRQSW0,
75                   kIRQHW0,
76                   kIRQHL0,
77                   kIA1IRQ0,
78                   kIA1IRQ1,
79                   kIA1IRQ2,
80                   kIA1IRQ3,
81                   kIA1IRQ4,
82                   kIA1IRQ5,
83                   kIA1IRQ6,
84                   kIA1IRQ7,
85                   kIA1IRQ8,
86                   kIA1IRQ9,
87                   kIA1IRQA,
88                   kIA1IRQB,
89                   kIA1IRQC,
90                   kIRQSW1,
91                   kIRQHW1,
92                   kIRQHL1,
93                   kIA2IRQ0,
94                   kIA2IRQ1,
95                   kIA2IRQ2,
96                   kIA2IRQ3,
97                   kIA2IRQ4,
98                   kIA2IRQ5,
99                   kIA2IRQ6,
100                   kIA2IRQ7,
101                   kIA2IRQ8,
102                   kIA2IRQ9,
103                   kIA2IRQA,
104                   kIA2IRQB,
105                   kIA2IRQC,
106                   kIRQSW2,
107                   kIRQHW2,
108                   kIRQHL2,
109                   kIA3IRQ0,
110                   kIA3IRQ1,
111                   kIA3IRQ2,
112                   kIA3IRQ3,
113                   kIA3IRQ4,
114                   kIA3IRQ5,
115                   kIA3IRQ6,
116                   kIA3IRQ7,
117                   kIA3IRQ8,
118                   kIA3IRQ9,
119                   kIA3IRQA,
120                   kIA3IRQB,
121                   kIA3IRQC,
122                   kIRQSW3,
123                   kIRQHW3,
124                   kIRQHL3,
125                   kCTGDINI,
126                   kCTGCTRL,
127                   kC08CPU0,
128                   kC09CPU0,
129                   kC10CPU0,
130                   kC11CPU0,
131                   kC12CPUA,
132                   kC13CPUA,
133                   kC14CPUA,
134                   kC15CPUA,
135                   kC08CPU1,
136                   kC09CPU1,
137                   kC10CPU1,
138                   kC11CPU1,
139                   kC08CPU2,
140                   kC09CPU2,
141                   kC10CPU2,
142                   kC11CPU2,
143                   kC08CPU3,
144                   kC09CPU3,
145                   kC10CPU3,
146                   kC11CPU3,
147                   kNMOD,
148                   kNDLY,
149                   kNED,
150                   kNTRO,
151                   kNRRO,
152                   kNES,
153                   kNTP,
154                   kNBND,
155                   kNP0,
156                   kNP1,
157                   kNP2,
158                   kNP3,
159                   kNCUT,
160                   kTPPT0,
161                   kTPFS,
162                   kTPFE,
163                   kTPPGR,
164                   kTPPAE,
165                   kTPQS0,
166                   kTPQE0,
167                   kTPQS1,
168                   kTPQE1,
169                   kEBD,
170                   kEBAQA,
171                   kEBSIA,
172                   kEBSF,
173                   kEBSIM,
174                   kEBPP,
175                   kEBPC,
176                   kEBIS,
177                   kEBIT,
178                   kEBIL,
179                   kEBIN,
180                   kFLBY,
181                   kFPBY,
182                   kFGBY,
183                   kFTBY,
184                   kFCBY,
185                   kFPTC,
186                   kFPNP,
187                   kFPCL,
188                   kFGTA,
189                   kFGTB,
190                   kFGCL,
191                   kFTAL,
192                   kFTLL,
193                   kFTLS,
194                   kFCW1,
195                   kFCW2,
196                   kFCW3,
197                   kFCW4,
198                   kFCW5,
199                   kTPFP,
200                   kTPHT,
201                   kTPVT,
202                   kTPVBY,
203                   kTPCT,
204                   kTPCL,
205                   kTPCBY,
206                   kTPD,
207                   kTPCI0,
208                   kTPCI1,
209                   kTPCI2,
210                   kTPCI3,
211                   kADCMSK,
212                   kADCINB,
213                   kADCDAC,
214                   kADCPAR,
215                   kADCTST,
216                   kSADCAZ,
217                   kFGF0,
218                   kFGF1,
219                   kFGF2,
220                   kFGF3,
221                   kFGF4,
222                   kFGF5,
223                   kFGF6,
224                   kFGF7,
225                   kFGF8,
226                   kFGF9,
227                   kFGF10,
228                   kFGF11,
229                   kFGF12,
230                   kFGF13,
231                   kFGF14,
232                   kFGF15,
233                   kFGF16,
234                   kFGF17,
235                   kFGF18,
236                   kFGF19,
237                   kFGF20,
238                   kFGA0,
239                   kFGA1,
240                   kFGA2,
241                   kFGA3,
242                   kFGA4,
243                   kFGA5,
244                   kFGA6,
245                   kFGA7,
246                   kFGA8,
247                   kFGA9,
248                   kFGA10,
249                   kFGA11,
250                   kFGA12,
251                   kFGA13,
252                   kFGA14,
253                   kFGA15,
254                   kFGA16,
255                   kFGA17,
256                   kFGA18,
257                   kFGA19,
258                   kFGA20,
259                   kFLL00,
260                   kFLL01,
261                   kFLL02,
262                   kFLL03,
263                   kFLL04,
264                   kFLL05,
265                   kFLL06,
266                   kFLL07,
267                   kFLL08,
268                   kFLL09,
269                   kFLL0A,
270                   kFLL0B,
271                   kFLL0C,
272                   kFLL0D,
273                   kFLL0E,
274                   kFLL0F,
275                   kFLL10,
276                   kFLL11,
277                   kFLL12,
278                   kFLL13,
279                   kFLL14,
280                   kFLL15,
281                   kFLL16,
282                   kFLL17,
283                   kFLL18,
284                   kFLL19,
285                   kFLL1A,
286                   kFLL1B,
287                   kFLL1C,
288                   kFLL1D,
289                   kFLL1E,
290                   kFLL1F,
291                   kFLL20,
292                   kFLL21,
293                   kFLL22,
294                   kFLL23,
295                   kFLL24,
296                   kFLL25,
297                   kFLL26,
298                   kFLL27,
299                   kFLL28,
300                   kFLL29,
301                   kFLL2A,
302                   kFLL2B,
303                   kFLL2C,
304                   kFLL2D,
305                   kFLL2E,
306                   kFLL2F,
307                   kFLL30,
308                   kFLL31,
309                   kFLL32,
310                   kFLL33,
311                   kFLL34,
312                   kFLL35,
313                   kFLL36,
314                   kFLL37,
315                   kFLL38,
316                   kFLL39,
317                   kFLL3A,
318                   kFLL3B,
319                   kFLL3C,
320                   kFLL3D,
321                   kFLL3E,
322                   kFLL3F,
323                   kPASADEL,
324                   kPASAPHA,
325                   kPASAPRA,
326                   kPASADAC,
327                   kPASACHM,
328                   kPASASTL,
329                   kPASAPR1,
330                   kPASAPR0,
331                   kSADCTRG,
332                   kSADCRUN,
333                   kSADCPWR,
334                   kL0TSIM,
335                   kSADCEC,
336                   kSADCMC,
337                   kSADCOC,
338                   kSADCGTB,
339                   kSEBDEN,
340                   kSEBDOU,
341                   kTPL00,
342                   kTPL01,
343                   kTPL02,
344                   kTPL03,
345                   kTPL04,
346                   kTPL05,
347                   kTPL06,
348                   kTPL07,
349                   kTPL08,
350                   kTPL09,
351                   kTPL0A,
352                   kTPL0B,
353                   kTPL0C,
354                   kTPL0D,
355                   kTPL0E,
356                   kTPL0F,
357                   kTPL10,
358                   kTPL11,
359                   kTPL12,
360                   kTPL13,
361                   kTPL14,
362                   kTPL15,
363                   kTPL16,
364                   kTPL17,
365                   kTPL18,
366                   kTPL19,
367                   kTPL1A,
368                   kTPL1B,
369                   kTPL1C,
370                   kTPL1D,
371                   kTPL1E,
372                   kTPL1F,
373                   kTPL20,
374                   kTPL21,
375                   kTPL22,
376                   kTPL23,
377                   kTPL24,
378                   kTPL25,
379                   kTPL26,
380                   kTPL27,
381                   kTPL28,
382                   kTPL29,
383                   kTPL2A,
384                   kTPL2B,
385                   kTPL2C,
386                   kTPL2D,
387                   kTPL2E,
388                   kTPL2F,
389                   kTPL30,
390                   kTPL31,
391                   kTPL32,
392                   kTPL33,
393                   kTPL34,
394                   kTPL35,
395                   kTPL36,
396                   kTPL37,
397                   kTPL38,
398                   kTPL39,
399                   kTPL3A,
400                   kTPL3B,
401                   kTPL3C,
402                   kTPL3D,
403                   kTPL3E,
404                   kTPL3F,
405                   kTPL40,
406                   kTPL41,
407                   kTPL42,
408                   kTPL43,
409                   kTPL44,
410                   kTPL45,
411                   kTPL46,
412                   kTPL47,
413                   kTPL48,
414                   kTPL49,
415                   kTPL4A,
416                   kTPL4B,
417                   kTPL4C,
418                   kTPL4D,
419                   kTPL4E,
420                   kTPL4F,
421                   kTPL50,
422                   kTPL51,
423                   kTPL52,
424                   kTPL53,
425                   kTPL54,
426                   kTPL55,
427                   kTPL56,
428                   kTPL57,
429                   kTPL58,
430                   kTPL59,
431                   kTPL5A,
432                   kTPL5B,
433                   kTPL5C,
434                   kTPL5D,
435                   kTPL5E,
436                   kTPL5F,
437                   kTPL60,
438                   kTPL61,
439                   kTPL62,
440                   kTPL63,
441                   kTPL64,
442                   kTPL65,
443                   kTPL66,
444                   kTPL67,
445                   kTPL68,
446                   kTPL69,
447                   kTPL6A,
448                   kTPL6B,
449                   kTPL6C,
450                   kTPL6D,
451                   kTPL6E,
452                   kTPL6F,
453                   kTPL70,
454                   kTPL71,
455                   kTPL72,
456                   kTPL73,
457                   kTPL74,
458                   kTPL75,
459                   kTPL76,
460                   kTPL77,
461                   kTPL78,
462                   kTPL79,
463                   kTPL7A,
464                   kTPL7B,
465                   kTPL7C,
466                   kTPL7D,
467                   kTPL7E,
468                   kTPL7F,
469                   kMEMRW,
470                   kMEMCOR,
471                   kDMDELA,
472                   kDMDELS,
473                   kLastReg };   // enum of all TRAP registers, to be used for access to them
474
475   Bool_t SetTrapRegAlloc(TrapReg_t reg, Alloc_t mode) { return fRegisterValue[reg].Allocate(mode); }
476   Bool_t SetTrapReg(TrapReg_t reg, Int_t value, Int_t det);
477   Bool_t SetTrapReg(TrapReg_t reg, Int_t value, Int_t det, Int_t rob, Int_t mcm);
478
479   Int_t  GetTrapReg(TrapReg_t reg, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
480
481   void ResetRegs();
482
483   // data memory (DMEM)
484   Bool_t SetDmemAlloc(Int_t addr, Alloc_t mode);
485   Bool_t SetDmem(Int_t addr, UInt_t value, Int_t det);
486   Bool_t SetDmem(Int_t addr, UInt_t value, Int_t det, Int_t rob, Int_t mcm);
487   Bool_t SetDmem(Int_t addr, Int_t value) { return SetDmem(addr, (UInt_t) value); }
488   Bool_t SetDmem(Int_t addr, Int_t value, Int_t det, Int_t rob, Int_t mcm) { return SetDmem(addr, (UInt_t) value, det, rob, mcm); }
489
490   UInt_t GetDmemUnsigned(Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
491
492   void ResetDmem();
493
494   // access by 16-bit address
495   UInt_t Peek(Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
496   Bool_t Poke(Int_t addr, UInt_t value, Int_t det, Int_t rob, Int_t mcm);
497
498   // helper methods
499   const char* GetRegName(TrapReg_t reg)       const { return ((reg >= 0) && (reg < kLastReg)) ? fRegisterValue[reg].GetName() : ""; }
500   UShort_t    GetRegAddress(TrapReg_t reg)    const { return ((reg >= 0) && (reg < kLastReg)) ? fRegisterValue[reg].GetAddr() : 0; }
501   UShort_t    GetRegNBits(TrapReg_t reg)      const { return ((reg >= 0) && (reg < kLastReg)) ? fRegisterValue[reg].GetNbits() : 0; }
502   UInt_t      GetRegResetValue(TrapReg_t reg) const { return ((reg >= 0) && (reg < kLastReg)) ? fRegisterValue[reg].GetResetValue() : 0; }
503
504   TrapReg_t   GetRegByAddress(Int_t address) const;
505
506   Bool_t PrintTrapReg(TrapReg_t reg, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
507   Bool_t PrintTrapAddr(Int_t addr, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
508
509   void PrintMemDatx(ostream &os, Int_t addr) const;
510   void PrintMemDatx(ostream &os, Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
511   void PrintMemDatx(ostream &os, TrapReg_t reg) const;
512   void PrintMemDatx(ostream &os, TrapReg_t reg, Int_t det, Int_t rob, Int_t mcm) const;
513   void PrintDatx(ostream &os, UInt_t addr, UInt_t data, Int_t rob, Int_t mcm) const;
514
515   static const Int_t fgkDmemStartAddress  = 0xc000; // start address in TRAP GIO
516   static const Int_t fgkDmemWords = 0x400;          // number of words in DMEM
517
518   static const Int_t fgkImemStartAddress = 0xe000;  // start address in TRAP GIO
519   static const Int_t fgkImemWords = 0x1000;         // number of words in IMEM
520
521   static const Int_t fgkDbankStartAddress = 0xf000; // start address in TRAP GIO
522   static const Int_t fgkDbankWords = 0x0100;        // number of words in DBANK
523
524  protected:
525   void InitRegs();
526
527   class AliTRDtrapValue : public TObject {
528   public:
529     AliTRDtrapValue();
530     virtual ~AliTRDtrapValue() {}
531
532     virtual Bool_t Allocate(Alloc_t mode);
533
534   protected:
535     Bool_t SetData(UInt_t value);
536     Bool_t SetData(UInt_t value, Int_t det);
537     Bool_t SetData(UInt_t value, Int_t det, Int_t rob, Int_t mcm);
538
539     UInt_t GetData(Int_t det, Int_t rob, Int_t mcm) const;
540
541     Int_t  GetIdx(Int_t det, Int_t rob, Int_t mcm) const;
542
543   private:
544     AliTRDtrapValue(const AliTRDtrapValue &rhs); // not implemented
545     AliTRDtrapValue& operator=(const AliTRDtrapValue &rhs); // not implemented
546
547     Alloc_t  fAllocMode;        // allocation mode
548     Int_t    fSize;             // array size
549     UInt_t  *fData;             //[fSize] data array
550     Bool_t  *fValid;            //[fSize] valid flag
551
552     static const Int_t fgkSize[kAllocLast]; // required array dimension for different allocation modes
553
554     ClassDef(AliTRDtrapValue, 1);
555   };
556
557   class AliTRDtrapRegister : public AliTRDtrapValue {
558   public:
559     AliTRDtrapRegister();
560     virtual ~AliTRDtrapRegister();
561
562     void    Init(const char* name, Int_t addr, Int_t nBits, Int_t resetValue);
563     void    Reset() { SetData(fResetValue); }
564
565     Bool_t  SetValue(Int_t value, Int_t det) { return SetData(value, det); }
566     Bool_t  SetValue(Int_t value, Int_t det, Int_t rob, Int_t mcm) { return SetData(value, det, rob, mcm); }
567
568     Int_t   GetValue(Int_t det, Int_t rob, Int_t mcm) const { return GetData(det, rob, mcm); }
569
570     const char*  GetName() const { return fName.Data(); }
571     UShort_t GetAddr() const { return fAddr; }
572     UShort_t GetNbits() const { return fNbits; }
573     UInt_t   GetResetValue() const { return fResetValue; }
574
575   protected:
576     AliTRDtrapRegister(const AliTRDtrapRegister &rhs);
577     AliTRDtrapRegister& operator=(const AliTRDtrapRegister &rhs);
578
579     // fixed properties of the register
580     // which do not need to be stored
581     TString   fName;            //! Name of the register
582     UShort_t  fAddr;            //! Address in GIO of TRAP
583     UShort_t  fNbits;           //! Number of bits, from 1 to 32
584     UInt_t    fResetValue;      //! reset value
585
586     ClassDef(AliTRDtrapRegister, 1);
587   };
588
589   class AliTRDtrapDmemWord : public AliTRDtrapValue {
590   public:
591     AliTRDtrapDmemWord() : AliTRDtrapValue(), fName(""), fAddr(0) {}
592     virtual ~AliTRDtrapDmemWord() {}
593
594     void    Reset() { SetData(0); }
595
596     Bool_t  SetValue(UInt_t value, Int_t det) { return SetData(value, det); }
597     Bool_t  SetValue(UInt_t value, Int_t det, Int_t rob, Int_t mcm) { return SetData(value, det, rob, mcm); }
598
599     UInt_t  GetValue(Int_t det, Int_t rob, Int_t mcm) const { return GetData(det, rob, mcm); }
600
601     void    SetAddress(UShort_t addr) { fAddr = addr; fName.Form("DMEM 0x%04x", fAddr); }
602     const char* GetName() const { return fName.Data(); }
603
604   protected:
605     AliTRDtrapDmemWord(const AliTRDtrapDmemWord &rhs); // not implemented
606     AliTRDtrapDmemWord& operator=(const AliTRDtrapDmemWord &rhs); // not implemented
607
608     TString  fName;
609     UShort_t fAddr;             //! address
610
611     ClassDef(AliTRDtrapDmemWord, 1);
612   };
613
614   // configuration registers
615   AliTRDtrapRegister fRegisterValue[kLastReg];  // array of TRAP register values in use
616
617   // DMEM
618   AliTRDtrapDmemWord fDmem[fgkDmemWords]; // TRAP data memory
619
620   static const Int_t fgkMaxMcm;            // max. no. of MCMs to be treated
621   static const Int_t fgkMcmlistSize=256;     // list of MCMs to which a value has to be written
622
623   static Bool_t    fgRegAddressMapInitialized;
624   static TrapReg_t fgRegAddressMap[0x400 + 0x200 + 0x3];
625   static const Int_t fgkRegisterAddressBlockStart[];
626   static const Int_t fgkRegisterAddressBlockSize[];
627
628  private:
629   AliTRDtrapConfig& operator=(const AliTRDtrapConfig &rhs); // not implemented
630   AliTRDtrapConfig(const AliTRDtrapConfig& cfg); // not implemented
631
632   ClassDef(AliTRDtrapConfig, 3);
633 };
634
635 #endif