Cat
LSDelayChipV1.cpp
Go to the documentation of this file.
1 //$Id: LSDelayChipV1.h,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 // local include file
14 #include "LSDelayChipV1.h"
15 
16 //Basic reading operations...
18 {
19  //m_regConfig->io()->setAddress(confRegAddr + 128); //+128 = read
20  U8* buffer = m_regConfig->io()->dataU8();
21  buffer[2] = confRegAddr + 128;
22  if (m_regConfig->read().isFailure()) warning("LSDelayChipV1 configuration register read failure.");
23  else
24  {
25  m_rxConfigBits = ((U16)buffer[1] * 256) + (U16)buffer[0];
26  debug("Config. Register phase (@"+ itohs(confRegAddr) + ") = 0x" + itohs(m_rxConfigBits),"LSDCv1::configRegBulkRead");
27  }
28 
29  //return m_rxConfigBits;
30 }
31 
32 // SPI Configuration Data Frame:
33 // 1b 1b 5b 5b 1b 1b 2b
34 // LVDS Out en -N.U- Phase T&H (ADC) Phase INT !VCNT Out En DEBUG LOCUS
36 {
37  bool ok = checkConfigAddr(confRegAddr);
38  if(ok)
39  {
40  configRegBulkRead(confRegAddr);
41  m_rxConfig.lvdsOutEn = (m_rxConfigBits >> 15) & 0x01;
42  m_rxConfig.phaseTaHAdc = (m_rxConfigBits >> 9) & 0x1F;
43  m_rxConfig.phaseInt = (m_rxConfigBits >> 4) & 0x1F;
44  m_rxConfig.nVControlEn = (m_rxConfigBits >> 3) & 0x01;
45  m_rxConfig.padDebug = (m_rxConfigBits >> 2) & 0x01;
47  m_configAddr = confRegAddr;
48 confRegData tmp = m_rxConfig;
49 configRegBulkRead(confRegAddr);
50 m_rxConfig = tmp;
51  }
52  else
53  warning("@" + itos(confRegAddr) + " is not a valid Configuration Register address.","LSDCv1::getConfigReg");
54 }
55 
56 //Basic writing operations...
58 {
59  U8* buffer = m_regConfig->io()->dataU8();
60  buffer[2] = confRegAddr;
61  buffer[1] = (confRegData >> 8) & 0xFF;
62  buffer[0] = confRegData & 0xFF;
63  if(m_regConfig->write().isFailure()) warning("LSDelayChipV1 configuration register write failure.");
64  else debug("Config. Register phase (@"+ itohs(confRegAddr) + ") = 0x" + itohs(confRegData),"LSDCv1::configRegBulkWrite");
65 }
66 
67 // SPI Configuration Data Frame:
68 // 1b 1b 5b 5b 1b 1b 2b
69 // LVDS Out en -N.U- Phase T&H (ADC) Phase INT !VCNT Out En DEBUG LOCUS
71 {
72  U16 data;
73  bool ok = checkConfigAddr(confRegAddr);
74  if(ok)
75  {
76  data = ((d.lvdsOutEn & 0x01) << 15) | ((d.phaseTaHAdc & 0x1F) << 9) | ((d.phaseInt & 0x1F) << 4) | ((d.nVControlEn & 0x01) << 3) | ((d.padDebug & 0x01) << 2) | (d.locus & 0x03);
77  configRegBulkWrite(confRegAddr,data);
78 configRegBulkWrite(confRegAddr,data);
79  }
80  else
81  warning("@" + itos(confRegAddr) + " is not a valid Configuration Register address.","LSDCv1::setConfigReg");
82 }
83 
85 // Safe way to modify data: data is read from the register and
86 // then we modify the value that we want.
87 void LSDelayChipV1::setConfigRegPhaseADC(U8 confRegAddr, U8 phaseADC)
88 {
89  getConfigReg(confRegAddr);
90  m_rxConfig.phaseTaHAdc = phaseADC;
91  setConfigReg(confRegAddr,m_rxConfig);
92 }
93 
94 void LSDelayChipV1::setConfigRegPhaseTH(U8 confRegAddr, U8 phaseTH)
95 {
96  getConfigReg(confRegAddr);
97  m_rxConfig.phaseTaHAdc = phaseTH;
98  setConfigReg(confRegAddr,m_rxConfig);
99 }
100 
101 void LSDelayChipV1::setConfigRegPhaseINT(U8 confRegAddr, U8 phaseINT)
102 {
103  getConfigReg(confRegAddr);
104  m_rxConfig.phaseInt = phaseINT;
105  setConfigReg(confRegAddr,m_rxConfig);
106 }
107 
108 void LSDelayChipV1::setConfigRegLVDSOutEn(U8 confRegAddr, bool en)
109 {
110  getConfigReg(confRegAddr);
111  m_rxConfig.lvdsOutEn = en;
112  setConfigReg(confRegAddr,m_rxConfig);
113 }
114 
115 void LSDelayChipV1::setConfigRegDebugMode(U8 confRegAddr, bool en)
116 {
117  getConfigReg(confRegAddr);
118  m_rxConfig.padDebug = en;
119  setConfigReg(confRegAddr,m_rxConfig);
120 }
121 
123 {
124  getConfigReg(confRegAddr);
125  m_rxConfig.nVControlEn = !en;
126  setConfigReg(confRegAddr,m_rxConfig);
127 }
128 
129 void LSDelayChipV1::setConfigRegLOCUS(U8 confRegAddr, U8 locus)
130 {
131  getConfigReg(confRegAddr);
132  m_rxConfig.locus = locus;
133  setConfigReg(confRegAddr,m_rxConfig);
134 }
137 
138 //Commands...
140 {
142 }
143 
145 {
147 }
148 
149 //Info...
151 {
152  std::string lvdsCurrent;
154  {
155  if(m_rxConfig.locus == LOCUS_3000_UA) lvdsCurrent = "3.00";
156  if(m_rxConfig.locus == LOCUS_2300_UA) lvdsCurrent = "2.30";
157  if(m_rxConfig.locus == LOCUS_1400_UA) lvdsCurrent = "1.40";
158  if(m_rxConfig.locus == LOCUS_0350_UA) lvdsCurrent = "0.35";
159  }
160  else lvdsCurrent = "0.00";
161 
162  info("Configuration register @SPI = 0x" + itohs(m_configAddr) ,"LSDCv1::showConfig");
163  info("Integrator clock phase (ns) = " + itos(m_rxConfig.phaseInt) ,"LSDCv1::showConfig");
164  info("T&H // ADC clock phase (ns) = " + itos(m_rxConfig.phaseTaHAdc) ,"LSDCv1::showConfig");
165  info("LVDS Clock Output enable = " + itos((int)m_rxConfig.lvdsOutEn) ,"LSDCv1::showConfig");
166  info("LVDS Output Current (mA) = " + lvdsCurrent ,"LSDCv1::showConfig");
167  info("VControl Output enable = " + itos((int)!m_rxConfig.nVControlEn) ,"LSDCv1::showConfig");
168  info("CMOS Pads debug = " + itos((int)m_rxConfig.padDebug) ,"LSDCv1::showConfig");
169 }
170 
171 
173 // SPI Slave BER Test //
175 void LSDelayChipV1::spiBERTest(U8 confRegAddr, long nFrames)
176 {
177  int i;
178  U16 writeData = 0x0000;
179  U16 readData, retry1, retry2, retry3;
180 
181  warning("Starting SPI BER test...");
182  m_nBad = 0;
183  for(i=0;i<nFrames;i++)
184  {
185  //I read and write the same register and I check if read data is OK.
186  writeData = rand() + rand();
187  configRegBulkWrite(confRegAddr,writeData);
188 configRegBulkWrite(255,writeData);
189  configRegBulkRead(confRegAddr);
190 configRegBulkWrite(255,writeData);
191  readData = m_rxConfigBits;
192  if(writeData != readData)
193  {
194  //If data is not OK I check how many bits are wrong.
195  m_nBad++;
196  warning("Mismatch: W = 0x" + itohs(writeData) + ", R = 0x" + itohs(readData) + ".","LSDCv1::spiBERTest");
197  debug("Retry...","LSDCv1::spiBERTest");
198  configRegBulkRead(confRegAddr);
199 configRegBulkWrite(255,writeData);
200  retry1 = m_rxConfigBits;
201  configRegBulkRead(confRegAddr);
202 configRegBulkWrite(255,writeData);
203  retry2 = m_rxConfigBits;
204  configRegBulkRead(confRegAddr);
205 configRegBulkWrite(255,writeData);
206  retry3 = m_rxConfigBits;
207  if(retry1 == retry2 && retry1 == retry3 && retry2 == retry3)
208  {
209  if(retry1 == readData) warning("It was a Write error!","LSDCv1::spiBERTest");
210  if(retry1 == writeData) warning("It was a Read error!","LSDCv1::spiBERTest");
211  }
212  }
213  }
214  m_fer = (double) m_nBad / nFrames;
215  warning("SPI BER test finished!!!");
216  warning("Bad frames = " + itos(m_nBad) + "/" + itos(nFrames) + ".");
217 }
218 
219 
221 /*
222  U8* buffer=m_regConfig->io()->dataU8();
223  buffer[2]=64;
224  buffer[1]=0;
225  buffer[0]=0;
226  if (m_regConfig->write().isFailure()){
227  warning("LSDelayChipV1 configuration register write failure. Cannot reset LSDelayChipV1",
228  "LSDCv1::write");
229  }
230  */
231 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
#define CHARGEPUMP_SOFT_RST
Definition: LSDelayChipV1.h:38
bool isFailure() const
Definition: StatusCode.h:68
Register * m_regConfig
void setConfigRegVControlOutEn(U8 confRegAddr, bool en)
confRegData m_rxConfig
void configRegBulkRead(U8 confRegAddr)
void setConfigRegPhaseTH(U8 confRegAddr, U8 phaseTH)
virtual StatusCode write()
Definition: IOobject.h:80
virtual StatusCode read()
Definition: IOobject.h:73
bool nVControlEn
Definition: LSDelayChipV1.h:47
void configRegBulkWrite(U8 confRegAddr, U16 confRegData)
unsigned char U8
Definition: ICECALv3.h:55
void debug(std::string mymsg)
Definition: Object.h:37
def data(object, stream=None)
Definition: shell.py:150
void getConfigReg(U8 confRegAddr)
void bypassMisoMosi(U16 writeData)
void setConfigRegLOCUS(U8 confRegAddr, U8 locus)
void setConfigRegLVDSOutEn(U8 confRegAddr, bool en)
#define SC_MOSI_MISO_BYPASS
Definition: ICECALv3.h:33
void setConfigReg(U8 confRegAddr, confRegData d)
U8 * dataU8()
Definition: IOdata.h:214
void setConfigRegPhaseINT(U8 confRegAddr, U8 phaseINT)
std::string itohs(U16 value)
void spiBERTest(U8 confRegAddr, long nFrames)
unsigned short U16
Definition: ICECALv3.h:54
void setConfigRegDebugMode(U8 confRegAddr, bool en)
void setConfigRegPhaseADC(U8 confRegAddr, U8 phaseADC)
void warning(std::string mymsg)
Definition: Object.h:39
bool checkConfigAddr(U8 addr)
IOdata * io()
Definition: IOobject.h:66