Cat
LSDelayChipV1.h
Go to the documentation of this file.
1 //$Id: LSDelayChipV1.cpp,v 1.0 2013/11/11 13:11:24 jmauricio Exp $
2 //------------------------------------------------------------------------------
3 //
4 // Package : LSDelayChipV1
5 //
6 // Description:
7 //
8 // Author(s) : Joan Mauricio
9 // Date : 2013/11/11
10 //
11 //------------------------------------------------------------------------------
12 
13 #ifndef __LSDelayChipV1_H_
14 #define __LSDelayChipV1_H_
15 
16 #include "Element.h"
17 #include "Register.h"
18 #include <stdlib.h>
19 
20 //Delay Line (standalone) SPI @ mapping.
21 //Integrator + Track & Hold Clock configuration registers.
22 #define INT_TH_0_CONFREG_ADDR 0x00
23 #define INT_TH_1_CONFREG_ADDR 0x02
24 #define INT_TH_2_CONFREG_ADDR 0x10
25 #define INT_TH_3_CONFREG_ADDR 0x12
26 //ADC Clock configuration registers.
27 #define ADC_0_CONFREG_ADDR 0x01
28 #define ADC_1_CONFREG_ADDR 0x03
29 #define ADC_2_CONFREG_ADDR 0x11
30 #define ADC_3_CONFREG_ADDR 0x13
31 //DLL channel status registers.
32 #define DLL_0_STATREG_ADDR 0xA0
33 #define DLL_1_STATREG_ADDR 0xA1
34 #define DLL_2_STATREG_ADDR 0xB0
35 #define DLL_3_STATREG_ADDR 0xB1
36 
37 //SPI commands.
38 #define CHARGEPUMP_SOFT_RST 0x40
39 #define SC_MOSI_MISO_BYPASS 0xFF
40 
41  typedef unsigned long U32;
42  typedef unsigned short U16;
43  typedef unsigned char U8;
44 
45  struct confRegData{
46  bool lvdsOutEn;
48  bool padDebug;
52  };
53 
54  struct statRegData{
55  bool dllLocked;
58  };
59 
60  typedef enum
61  {
62  LOCUS_3000_UA = 0, // 3.0 mA
63  LOCUS_1400_UA = 1, // 1.4 mA
64  LOCUS_2300_UA = 2, // 2.3 mA
65  LOCUS_0350_UA = 3 // .35 mA
67 
68 class LSDelayChipV1 : public Element {
69 public:
70 
72  setType("LSDelayChipV1");
73  setId(0);
74 
76  debug("LSDelayChipV1 built.","LSDelayChipV1::LSDelayChipV1");
77 
78  m_regConfig=new Register();
79  m_regStatus=new Register();
80 
81  m_regConfig->setName("ConfigRegister");
82  m_regStatus->setName("StatusRegister");
83 
84  m_regConfig->io()->setSubAddress(9);
85  m_regStatus->io()->setSubAddress(19);
86 
87  m_regConfig->io()->defDataU8(3);
88  m_regStatus->io()->defDataU8(2);
89 
90  m_regConfig->io()->setWordSize(IOdata::Byte);
91  m_regStatus->io()->setWordSize(IOdata::Byte);
92 
93  addChild(m_regConfig);
94  addChild(m_regStatus);
95  m_configAddr = 0xEE;
96  }
97 
98  //Core functions: access to configuration registers.
99  //Bulk R/W : 'naked' bits.
100  //Set / Get : confRegData struct is used to store values.
101  void configRegBulkRead (U8 confRegAddr);
102  void configRegBulkWrite (U8 confRegAddr, U16 confRegData);
103  void getConfigReg (U8 confRegAddr);
104  void setConfigReg (U8 confRegAddr, confRegData d);
105 
106  //Safe way to write single data within the registers.
107  void setConfigRegPhaseADC (U8 confRegAddr, U8 phaseADC);
108  void setConfigRegPhaseTH (U8 confRegAddr, U8 phaseTH );
109  void setConfigRegPhaseINT (U8 confRegAddr, U8 phaseINT);
110  void setConfigRegLVDSOutEn (U8 confRegAddr, bool en);
111  void setConfigRegDebugMode (U8 confRegAddr, bool en);
112  void setConfigRegVControlOutEn (U8 confRegAddr, bool en);
113  void setConfigRegLOCUS (U8 confRegAddr, U8 locus);
114 
115  //Commands:
116  void resetPumps();
117  void bypassMisoMosi(U16 writeData);
118 
119  //FER (Frame Error Rate) Test.
120  void spiBERTest(U8 confRegAddr, long nFrames);
121 
122  //Shows the content of the last polled configuration register.
123  void showConfig();
124 
126  }
127 
131  void help() { info("LSDelayChipV1 "+name()+". No help.","LSDelayChipV1::help"); };
132 
139  return StatusCode::SUCCESS;
140  };
141 
149  void reset();
150 
154  void update () {
155 
156  };
157 
158  void setAddress(U8 address){
159  m_address=address;
160  m_regConfig->setAddress(m_address);
161  m_regStatus->setAddress(m_address);
162  }
163 
164 private:
165 
169 
171  confRegData m_rxConfig;
173 
174  long m_nBad;
175  double m_fer;
176 
177  bool checkConfigAddr(U8 addr)
178  {
179  bool ok = false;
180  ok |= (addr == INT_TH_0_CONFREG_ADDR);
181  ok |= (addr == INT_TH_1_CONFREG_ADDR);
182  ok |= (addr == INT_TH_2_CONFREG_ADDR);
183  ok |= (addr == INT_TH_3_CONFREG_ADDR);
184  ok |= (addr == ADC_0_CONFREG_ADDR);
185  ok |= (addr == ADC_1_CONFREG_ADDR);
186  ok |= (addr == ADC_2_CONFREG_ADDR);
187  ok |= (addr == ADC_3_CONFREG_ADDR);
188  if(ok) debug("The address @" + itos(addr) + " is valid.");
189  else debug("The address @" + itos(addr) + " is not valid.");
190  return ok;
191  }
192 
193  bool checkStatusAddr(U8 addr)
194  {
195  bool ok = false;
196  ok |= (addr == DLL_0_STATREG_ADDR);
197  ok |= (addr == DLL_1_STATREG_ADDR);
198  ok |= (addr == DLL_2_STATREG_ADDR);
199  ok |= (addr == DLL_3_STATREG_ADDR);
200  if(ok) debug("The address @" + itos(addr) + " is valid.");
201  else debug("The address @" + itos(addr) + " is not valid.");
202  return ok;
203  }
204 
205  std::string itohs(U16 value)
206  {
207  char buff[32];
208  sprintf(buff,"%04X",value);
209  return std::string(buff);
210  }
211 };
212 
213 #endif
214 
#define ADC_3_CONFREG_ADDR
Definition: LSDelayChipV1.h:30
std::string itos(int)
Definition: Tools.cpp:46
Register * m_regConfig
confRegData m_rxConfig
#define DLL_0_STATREG_ADDR
Definition: LSDelayChipV1.h:32
unsigned long U32
Definition: LSDelayChipV1.h:41
bool warningDllFast
Definition: LSDelayChipV1.h:56
#define DLL_3_STATREG_ADDR
Definition: LSDelayChipV1.h:35
#define INT_TH_2_CONFREG_ADDR
Definition: LSDelayChipV1.h:24
LVDS_OUTPUT_CURRENT_SELECTOR
Definition: LSDelayChipV1.h:60
void setAddress(U8 address)
#define INT_TH_0_CONFREG_ADDR
Definition: LSDelayChipV1.h:22
#define ADC_0_CONFREG_ADDR
Definition: LSDelayChipV1.h:27
bool errorDllSlow
Definition: LSDelayChipV1.h:57
bool nVControlEn
Definition: LSDelayChipV1.h:47
#define INT_TH_1_CONFREG_ADDR
Definition: LSDelayChipV1.h:23
unsigned char U8
Definition: ICECALv3.h:55
#define INT_TH_3_CONFREG_ADDR
Definition: LSDelayChipV1.h:25
Register * m_regStatus
bool checkStatusAddr(U8 addr)
#define DLL_1_STATREG_ADDR
Definition: LSDelayChipV1.h:33
#define ADC_2_CONFREG_ADDR
Definition: LSDelayChipV1.h:29
unsigned char U8
Definition: LSDelayChipV1.h:43
std::string itohs(U16 value)
StatusCode init()
#define ADC_1_CONFREG_ADDR
Definition: LSDelayChipV1.h:28
unsigned short U16
Definition: ICECALv3.h:54
def reset(path='')
Definition: shell.py:212
bool checkConfigAddr(U8 addr)
unsigned short U16
Definition: LSDelayChipV1.h:42
#define DLL_2_STATREG_ADDR
Definition: LSDelayChipV1.h:34