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