21 debug(
"ICECALv3 built.",
"ICECALv3::ICECALv3");
39 int paramValue[64], nParams;
42 PyObject* fullConfiguration = PyList_New(0);
44 string mainParams[] = {
"VCONTROL_OE",
"BXID_SYN_OE",
"CLK_REFRESH",
"IBIAS_OB",
"IBIAS_CE_TH",
"IBIAS_TH",
"IBIAS_INT",
"IBIAS_CE_IN",
"IBIAS_CE_PZ",
"IBIAS_0T",
"IBIAS_PZ",
"IBIAS_V0T"};
45 string analogParams[4][7]= { {
"CINT_SUBCH0[0]",
"CINT_SUBCH1[0]",
"IOFF_SUBCH0[0]",
"IOFF_SUBCH1[0]",
"ZERO[0]",
"POLE[0]",
"ZIN[0]"}
46 , {
"CINT_SUBCH0[1]",
"CINT_SUBCH1[1]",
"IOFF_SUBCH0[1]",
"IOFF_SUBCH1[1]",
"ZERO[1]",
"POLE[1]",
"ZIN[1]"}
47 , {
"CINT_SUBCH0[2]",
"CINT_SUBCH1[2]",
"IOFF_SUBCH0[2]",
"IOFF_SUBCH1[2]",
"ZERO[2]",
"POLE[2]",
"ZIN[2]"}
48 , {
"CINT_SUBCH0[3]",
"CINT_SUBCH1[3]",
"IOFF_SUBCH0[3]",
"IOFF_SUBCH1[3]",
"ZERO[3]",
"POLE[3]",
"ZIN[3]"} };
49 string delayLineParams[4][5]= { {
"PHASE_ADC[0]",
"PHASE_TH[0]",
"PHASE_INT[0]",
"LOC_SEL[0]",
"LVDS_OEN[0]"}
50 ,{
"PHASE_ADC[1]",
"PHASE_TH[1]",
"PHASE_INT[1]",
"LOC_SEL[1]",
"LVDS_OEN[1]"}
51 ,{
"PHASE_ADC[2]",
"PHASE_TH[2]",
"PHASE_INT[2]",
"LOC_SEL[2]",
"LVDS_OEN[2]"}
52 ,{
"PHASE_ADC[3]",
"PHASE_TH[3]",
"PHASE_INT[3]",
"LOC_SEL[3]",
"LVDS_OEN[3]"} };
60 asicParams =
fillParams(mainParams,12,paramName,paramValue,nParams);
62 PyList_Append(fullConfiguration,asicParams);
64 for(
int iCh=0 ; iCh<4 ; iCh++)
66 asicParams =
fillParams(analogParams[iCh],7,paramName,paramValue,nParams);
68 PyList_Append(fullConfiguration,asicParams);
69 asicParams =
fillParams(delayLineParams[iCh],5,paramName,paramValue,nParams);
71 PyList_Append(fullConfiguration,asicParams);
74 return fullConfiguration;
79 int iParams = 0, eqPos;
82 std::ifstream fd(configFile.c_str());
85 error(configFile+
" could not be opened.",
"ICECALv3::loadConfig");
93 eqPos = line.find(
"=");
94 if((eqPos != string::npos) && (line[0] !=
'#'))
96 paramName[iParams] = line.substr(0,eqPos);
97 paramValue[iParams] = atoi(line.substr(eqPos+1,string::npos).c_str());
106 PyObject*
ICECALv3::fillParams(
string paramListRet[],
int paramListLen,
string paramName[64],
int paramValue[64],
int fileParamLen)
110 PyObject* asicParams = PyList_New(0);
113 for(
int iList=0 ; iList<paramListLen ; iList++)
118 while(iParamFile < fileParamLen && !found)
120 if(paramName[iParamFile].find(paramListRet[iList]) != string::npos)
122 PyList_Append(asicParams, PyInt_FromLong(paramValue[iParamFile]));
134 PyObject* asicParams = PyList_New(0);
138 PyList_Append(asicParams, chipId);
159 struct tm * timeinfo;
160 char dStr[64], tStr[64];
170 timeinfo = localtime (&rawtime);
171 strftime (dStr,64,
"%Y/%m/%d",timeinfo);
172 strftime (tStr,64,
"%R",timeinfo);
174 fd.open (fileName.c_str(), ios_base::out);
177 fd <<
"#########################################################" << endl;
178 fd <<
"############# ICECAL CALIBRATION FILE ###############" << endl;
179 fd <<
"#########################################################" << endl;
182 fd <<
"#Date (YYYY/MM/DD): " << string(dStr) << endl;
183 fd <<
"#Time (HH:MM) : " << string(tStr) << endl;
184 fd <<
"#ICECAL Chip ID : " << PyString_AsString(PyList_GetItem(asicParams,0)) << endl;
185 fd <<
"" << endl << endl;
187 fd <<
"#########################################################" << endl;
188 fd <<
"# ICECAL Main Register Parameters:" << endl;
189 fd <<
"#########################################################" << endl;
192 l = PyList_GetItem(asicParams,9);
193 fd <<
"VCONTROL_OE = " << PyInt_AsLong(PyList_GetItem(l,0)) << endl;
194 fd <<
"BXID_SYN_OE = " << PyInt_AsLong(PyList_GetItem(l,1)) << endl;
195 fd <<
"CLK_REFRESH = " << PyInt_AsLong(PyList_GetItem(l,2)) << endl;
196 fd <<
"IBIAS_OB = " << PyInt_AsLong(PyList_GetItem(l,3)) << endl;
197 fd <<
"IBIAS_CE_TH = " << PyInt_AsLong(PyList_GetItem(l,4)) << endl;
198 fd <<
"IBIAS_TH = " << PyInt_AsLong(PyList_GetItem(l,5)) << endl;
199 fd <<
"IBIAS_INT = " << PyInt_AsLong(PyList_GetItem(l,6)) << endl;
200 fd <<
"IBIAS_CE_IN = " << PyInt_AsLong(PyList_GetItem(l,7)) << endl;
201 fd <<
"IBIAS_CE_PZ = " << PyInt_AsLong(PyList_GetItem(l,8)) << endl;
202 fd <<
"IBIAS_0T = " << PyInt_AsLong(PyList_GetItem(l,9)) << endl;
203 fd <<
"IBIAS_PZ = " << PyInt_AsLong(PyList_GetItem(l,10)) << endl;
204 fd <<
"IBIAS_V0T = " << PyInt_AsLong(PyList_GetItem(l,11)) << endl;
205 fd <<
"" << endl << endl;
209 fd <<
"#########################################################" << endl;
210 fd <<
"#Channel #" << i <<
" Parameters:" << endl;
211 fd <<
"#########################################################" << endl;
214 l = PyList_GetItem(asicParams,1+2*i);
215 fd <<
"PHASE_ADC[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,0)) << endl;
216 fd <<
"PHASE_TH[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,1)) << endl;
217 fd <<
"PHASE_INT[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,2)) << endl;
218 fd <<
"LOC_SEL[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,3)) << endl;
219 fd <<
"LVDS_OEN[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,4)) << endl;
221 l = PyList_GetItem(asicParams,2+2*i);
222 fd <<
"CINT_SUBCH0[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,0)) << endl;
223 fd <<
"CINT_SUBCH1[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,1)) << endl;
224 fd <<
"IOFF_SUBCH0[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,2)) << endl;
225 fd <<
"IOFF_SUBCH1[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,3)) << endl;
226 fd <<
"ZERO[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,4)) << endl;
227 fd <<
"POLE[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,5)) << endl;
228 fd <<
"ZIN[" << i <<
"] = " << PyInt_AsLong(PyList_GetItem(l,6)) << endl;
251 int phaseADC, phaseTH, phaseINT, locSel, lvdsOEn;
252 PyObject* dllParams = PyList_New(0);
254 if(
err) PyList_Append(dllParams, PyInt_FromLong(-1));
257 phaseADC = (rxData >> 11) & 0x1F;
258 phaseTH = (rxData >> 6 ) & 0x1F;
259 phaseINT = (rxData >> 3 ) & 0x07;
260 locSel = (rxData >> 1 ) & 0x03;
261 lvdsOEn = (rxData & 0x01);
264 PyList_Append(dllParams, PyInt_FromLong(phaseADC));
265 PyList_Append(dllParams, PyInt_FromLong(phaseTH));
266 PyList_Append(dllParams, PyInt_FromLong(phaseINT));
267 PyList_Append(dllParams, PyInt_FromLong(locSel));
268 PyList_Append(dllParams, PyInt_FromLong(lvdsOEn));
270 info(
"Delay Line Channel <"+
itos(ch)+
"> configuration (@SPI = 0x"+
itohs(spiAddr)+
"):",
"ICECALv3::getDelayLine");
271 info(
" ·Phase ADC : "+
itos(phaseADC),
"ICECALv3::getDelayLine");
272 info(
" ·Phase T&H : "+
itos(phaseTH) ,
"ICECALv3::getDelayLine");
273 info(
" ·Phase INT : "+
itos(phaseINT),
"ICECALv3::getDelayLine");
274 info(
" ·LVDS Current Sel : "+
itos(locSel) ,
"ICECALv3::getDelayLine");
275 info(
" ·LVDS Output enable : "+
itos(lvdsOEn) ,
"ICECALv3::getDelayLine");
284 int phaseADC, phaseTH, phaseINT, locSel, lvdsOEn;
289 phaseADC = PyInt_AsLong(PyList_GetItem(dllParams,0));
290 phaseTH = PyInt_AsLong(PyList_GetItem(dllParams,1));
291 phaseINT = PyInt_AsLong(PyList_GetItem(dllParams,2));
292 locSel = PyInt_AsLong(PyList_GetItem(dllParams,3));
293 lvdsOEn = PyInt_AsLong(PyList_GetItem(dllParams,4));
296 txData = ((phaseADC & 0x1F) << 11) | ((phaseTH & 0x1F) << 6) | ((phaseINT & 0x1F) << 3) | ((locSel & 0x03) << 1) | (lvdsOEn & 0x01);
317 int cIntMsb, cIntLsb0, cIntLsb1, iOffMsb, cIntSubCh0, cIntSubCh1, iOffLsb0, iOffLsb1, iOffSubCh0, iOffSubCh1, zero, pole, zIn;
318 PyObject* icecalChParams = PyList_New(0);
323 if(
err) PyList_Append(icecalChParams, PyInt_FromLong(-1));
326 cIntMsb = (rxData >> 30) & 0x03;
327 cIntLsb0 = (rxData >> 27) & 0x07;
328 cIntLsb1 = (rxData >> 24) & 0x07;
329 iOffMsb = (rxData >> 20) & 0x0F;
330 iOffLsb0 = (rxData >> 18) & 0x03;
331 iOffLsb1 = (rxData >> 16) & 0x03;
332 zero = (rxData >> 11) & 0x1F;
333 pole = (rxData >> 5) & 0x3F;
334 zIn = (rxData) & 0x1F;
336 cIntSubCh0 = (cIntMsb << 3) | cIntLsb0;
337 cIntSubCh1 = (cIntMsb << 3) | cIntLsb1;
338 iOffSubCh0 = (iOffMsb << 2) | iOffLsb0;
339 iOffSubCh1 = (iOffMsb << 2) | iOffLsb1;
341 PyList_Append(icecalChParams, PyInt_FromLong(cIntSubCh0));
342 PyList_Append(icecalChParams, PyInt_FromLong(cIntSubCh1));
343 PyList_Append(icecalChParams, PyInt_FromLong(iOffSubCh0));
344 PyList_Append(icecalChParams, PyInt_FromLong(iOffSubCh1));
345 PyList_Append(icecalChParams, PyInt_FromLong(zero));
346 PyList_Append(icecalChParams, PyInt_FromLong(pole));
347 PyList_Append(icecalChParams, PyInt_FromLong(zIn));
349 info(
"ICECAL Analog Channel <"+
itos(ch)+
"> (MSB @SPI = 0x"+
itohs(spiMsbAddr)+
". LSB @SPI = 0x"+
itohs(spiLsbAddr)+
"):",
"ICECALv3::getIcecal");
350 info(
" ·Integrator capacitor SubCh<0> : "+
itos(cIntSubCh0) ,
"ICECALv3::getAnalogCh");
351 info(
" ·Integrator capacitor SubCh<1> : "+
itos(cIntSubCh1) ,
"ICECALv3::getAnalogCh");
352 info(
" ·Offset Current SubCh<0> : "+
itos(iOffSubCh0) ,
"ICECALv3::getAnalogCh");
353 info(
" ·Offset Current SubCh<1> : "+
itos(iOffSubCh1) ,
"ICECALv3::getAnalogCh");
354 info(
" ·PZ Zero capacitor : "+
itos(zero) ,
"ICECALv3::getAnalogCh");
355 info(
" ·PZ Pole capacitor : "+
itos(pole) ,
"ICECALv3::getAnalogCh");
356 info(
" ·Input impedance control : "+
itos(zIn) ,
"ICECALv3::getAnalogCh");
358 return icecalChParams;
364 int cIntMsb, cIntLsb0, cIntLsb1, cIntSubCh0, cIntSubCh1, iOffMsb, iOffLsb0, iOffLsb1;
365 int iOffSubCh0, iOffSubCh1, zero, pole, zIn;
370 cIntSubCh0 = PyInt_AsLong(PyList_GetItem(icecalChParams,0));
371 cIntSubCh1 = PyInt_AsLong(PyList_GetItem(icecalChParams,1));
372 iOffSubCh0 = PyInt_AsLong(PyList_GetItem(icecalChParams,2));
373 iOffSubCh1 = PyInt_AsLong(PyList_GetItem(icecalChParams,3));
374 zero = PyInt_AsLong(PyList_GetItem(icecalChParams,4));
375 pole = PyInt_AsLong(PyList_GetItem(icecalChParams,5));
376 zIn = PyInt_AsLong(PyList_GetItem(icecalChParams,6));
380 if(((cIntSubCh0 & 0x18) == (cIntSubCh1 & 0x18)) && ((iOffSubCh0 & 0x3C) == (iOffSubCh1 & 0x3C)))
383 cIntMsb = (cIntSubCh0 >> 3) & 0x3;
384 cIntLsb0 = cIntSubCh0 & 0x7;
385 cIntLsb1 = cIntSubCh1 & 0x7;
387 iOffMsb = (iOffSubCh0 >> 2) & 0xF;
388 iOffLsb0 = iOffSubCh0 & 0x3;
389 iOffLsb1 = iOffSubCh1 & 0x3;
391 hTx = ((cIntMsb & 0x3) << 14) | ((cIntLsb0 & 0x7) << 11) | ((cIntLsb1 & 0x7) << 8) |
392 ((iOffMsb & 0xF) << 4) | ((iOffLsb0 & 0x3) << 2) | ((iOffLsb1 & 0x3));
393 lTx = ((zero & 0x1F) << 11) | ((pole & 0x3F) << 5) | (zIn & 0x1F);
403 if((cIntSubCh0 & 0x18) != (cIntSubCh1 & 0x18))
error(
"Integrator Cap MSB sub-channel mismatch. MSB<0> = "+
itohs(cIntSubCh0)+
", MSB<1> = "+
itohs(cIntSubCh1)+
".",
"ICECALv3::setAnalogCh");
404 if((iOffSubCh0 & 0x3C) != (iOffSubCh1 & 0x3C))
error(
"Offset Current MSB sub-channel mismatch. MSB<0> = "+
itohs(iOffSubCh0)+
", MSB<1> = "+
itohs(iOffSubCh1)+
".",
"ICECALv3::setAnalogCh");
419 int vCtlOE, bxidSynOE, clkRefreshEn, iBiasOB, iBiasCETH, iBiasTH, iBiasINT;
420 int iBiasCEINT, iBiasCEPZ, iBias0T, iBiasPZ, iBiasV0T;
421 PyObject* icecalMainParams = PyList_New(0);
425 if(
err) PyList_Append(icecalMainParams, PyInt_FromLong(-1));
429 vCtlOE = !((rxD[3] >> 15) & 0x01);
430 bxidSynOE = !((rxD[3] >> 14) & 0x01);
431 clkRefreshEn = !((rxD[3] >> 13) & 0x01);
434 iBiasOB = (rxD[3] >> 6) & 0x3F;
435 iBiasCETH = (rxD[3]) & 0x3F;
436 iBiasTH = (rxD[2] >> 6) & 0x3F;
437 iBiasINT = (rxD[2] ) & 0x3F;
438 iBiasCEINT =((rxD[1] >> 9) & 0x38) | ((rxD[0] >> 12) & 0x7);
439 iBiasCEPZ = (rxD[1] >> 6) & 0x3F;
440 iBias0T = (rxD[1]) & 0x3F;
441 iBiasPZ = (rxD[0] >> 6) & 0x3F;
442 iBiasV0T = (rxD[0]) & 0x3F;
444 PyList_Append(icecalMainParams, PyInt_FromLong(vCtlOE));
445 PyList_Append(icecalMainParams, PyInt_FromLong(bxidSynOE));
446 PyList_Append(icecalMainParams, PyInt_FromLong(clkRefreshEn));
447 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasOB));
448 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasCETH));
449 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasTH));
450 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasINT));
451 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasCEINT));
452 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasCEPZ));
453 PyList_Append(icecalMainParams, PyInt_FromLong(iBias0T));
454 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasPZ));
455 PyList_Append(icecalMainParams, PyInt_FromLong(iBiasV0T));
458 info(
" ·DLL Control Voltage Output Enable: " +
itos(vCtlOE) ,
"ICECALv3::getIcecalMain");
459 info(
" ·BXID Resynch Output Enable : " +
itos(bxidSynOE) ,
"ICECALv3::getIcecalMain");
460 info(
" ·SPI Clock refresh Enable : " +
itos(clkRefreshEn) ,
"ICECALv3::getIcecalMain");
461 info(
" ·Output Buffer bias : " +
itos(iBiasOB) ,
"ICECALv3::getIcecalMain");
462 info(
" ·Track & Hold OpAmp bias (CE) : " +
itos(iBiasCETH) ,
"ICECALv3::getIcecalMain");
463 info(
" ·Track & Hold OpAmp bias : " +
itos(iBiasTH) ,
"ICECALv3::getIcecalMain");
464 info(
" ·Integrator OpAmp bias : " +
itos(iBiasINT) ,
"ICECALv3::getIcecalMain");
465 info(
" ·Integrator OpAmp bias (CE) : " +
itos(iBiasCEINT) ,
"ICECALv3::getIcecalMain");
466 info(
" ·Pole-Zero OpAmp bias (CE) : " +
itos(iBiasCEPZ) ,
"ICECALv3::getIcecalMain");
467 info(
" ·0T bias : " +
itos(iBias0T) ,
"ICECALv3::getIcecalMain");
468 info(
" ·Pole-Zero OpAmp bias : " +
itos(iBiasPZ) ,
"ICECALv3::getIcecalMain");
469 info(
" ·0T bias (V0T) : " +
itos(iBiasV0T) ,
"ICECALv3::getIcecalMain");
471 return icecalMainParams;
478 int vCtlOE, bxidSynOE, clkRefreshEn, iBiasOB, iBiasCETH, iBiasTH, iBiasINT;
479 int iBiasCEINT, iBiasCEPZ, iBias0T, iBiasPZ, iBiasV0T;
481 vCtlOE = !PyInt_AsLong(PyList_GetItem(icecalMainParams,0));
482 bxidSynOE = !PyInt_AsLong(PyList_GetItem(icecalMainParams,1));
483 clkRefreshEn = !PyInt_AsLong(PyList_GetItem(icecalMainParams,2));
484 iBiasOB = PyInt_AsLong(PyList_GetItem(icecalMainParams,3));
485 iBiasCETH = PyInt_AsLong(PyList_GetItem(icecalMainParams,4));
486 iBiasTH = PyInt_AsLong(PyList_GetItem(icecalMainParams,5));
487 iBiasINT = PyInt_AsLong(PyList_GetItem(icecalMainParams,6));
488 iBiasCEINT = PyInt_AsLong(PyList_GetItem(icecalMainParams,7));
489 iBiasCEPZ = PyInt_AsLong(PyList_GetItem(icecalMainParams,8));
490 iBias0T = PyInt_AsLong(PyList_GetItem(icecalMainParams,9));
491 iBiasPZ = PyInt_AsLong(PyList_GetItem(icecalMainParams,10));
492 iBiasV0T = PyInt_AsLong(PyList_GetItem(icecalMainParams,11));
494 txD[3] = ((vCtlOE & 0x1) << 15) | ((bxidSynOE & 0x1) << 14) | ((clkRefreshEn & 0x1) << 13) | ((iBiasOB & 0x3F) << 6) | (iBiasCETH & 0x3F);
495 txD[2] = ((iBiasTH & 0x3F) << 6) | (iBiasINT & 0x3F);
496 txD[1] = ((iBiasCEINT & 0x38) << 9) | ((iBiasCEPZ & 0x3F) << 6) | (iBias0T & 0x3F);
497 txD[0] = ((iBiasCEINT & 0x7) << 12) | ((iBiasPZ & 0x3F) << 6) | (iBiasV0T & 0x3F);
522 rxRegData =
spiRead(confRegAddr);
525 ok = (rxRegData == confRegData);
528 if(!ok)
warning(
"Mismatch ("+
itohs(iteration)+
") in @SPI = 0x"+
itohs(confRegAddr)+
". Read: 0x"+
itohs(rxRegData)+
". Expected: 0x"+
itohs(confRegAddr)+
".",
"ICECALv3::spiWriteSafe");
530 }
while(!ok && iteration<=
nRetries);
532 if(!ok)
error(
"Too many errors ("+
itohs(iteration)+
"). Check electronics!",
"ICECALv3::spiWriteSafe");
542 buffer[2] = confRegAddr + offsetAddr;
546 warning(
"ICECALv3 read (@"+
itohs(confRegAddr)+
") error.",
"ICECALv3::spiRead");
553 rxData = ((
U16)buffer[1] * 256) + (
U16)buffer[0];
554 debug(
"Register (@"+
itohs(confRegAddr) +
") = 0x" +
itohs(rxData),
"ICECALv3::spiRead");
564 buffer[2] = confRegAddr;
565 buffer[1] = (confRegData >> 8) & 0xFF;
566 buffer[0] = confRegData & 0xFF;
570 if(
err)
warning(
"ICECALv3 write error.",
"ICECALv3::spiWrite");
571 else debug(
"ICECALv3 write (@"+
itohs(confRegAddr) +
") = 0x" +
itohs(confRegData),
"ICECALv3::spiWrite");
579 long iTest, nBadTx=0, nBadRx=0, nFatal=0, nBad, regErrorHistogram[16];
580 int iFrame, iRetry, readOk, writeOk;
582 U16 writeData = 0x0000;
584 PyObject* ferStatistics = PyList_New(0);
585 PyObject* confRegAddresses = PyList_New(0);
586 PyObject* confRegHistogram = PyList_New(0);
590 icecalLSBAddrCh[0], icecalLSBAddrCh[1], icecalLSBAddrCh[2], icecalLSBAddrCh[3],
icecalMSBAddrCh[0] , icecalMSBAddrCh[1] , icecalMSBAddrCh[2] , icecalMSBAddrCh[3]};
593 for(
int i=0 ; i<16 ; i++) regErrorHistogram[i] = 0;
595 info(
"Starting SPI FER test...",
"ICECALv3::spiFERTest");
598 for(iTest=0 ; iTest<nTest ; iTest++)
601 for(iFrame=0 ; iFrame<16 ; iFrame++)
603 addr = confRegList[iFrame];
606 writeData = rand() + rand();
613 if(writeData != readData)
616 iRetry = 0; readOk = 0; writeOk = 0;
620 if(retry == readData ) readOk++;
621 if(retry == writeData) writeOk++;
624 while(readOk < 5 && writeOk < 5 && iRetry < 50);
627 if (iRetry >= 50) {
error(
"Mismatch: the source of the SPI error could not be determined",
"ICECALv3::spiFER"); nFatal++; }
628 else if (readOk >= 5) {
error(
"Mismatch: Write error @SPI = 0x"+
itohs(addr)+
". W = 0x"+
itohs(writeData)+
", R = 0x"+
itohs(readData)+
".",
"ICECALv3::spiFER"); nBadTx++; }
629 else {
error(
"Mismatch: Read error @SPI = 0x"+
itohs(addr)+
". W = 0x"+
itohs(writeData)+
", R = 0x"+
itohs(readData)+
".",
"ICECALv3::spiFER"); nBadRx++; }
632 regErrorHistogram[iFrame]++;
636 nBad = nFatal + nBadTx + nBadRx;
637 fer = (double)nBad / ((
double)nTest * 16.0);
639 for(iFrame=0 ; iFrame<16 ; iFrame++) PyList_Append(confRegAddresses, PyInt_FromLong(confRegList[iFrame]));
640 for(iFrame=0 ; iFrame<16 ; iFrame++) PyList_Append(confRegHistogram, PyInt_FromLong(regErrorHistogram[iFrame]));
643 PyList_Append(ferStatistics, PyInt_FromLong(nBad));
644 PyList_Append(ferStatistics, PyFloat_FromDouble(fer));
645 PyList_Append(ferStatistics, PyInt_FromLong(nFatal));
646 PyList_Append(ferStatistics, PyInt_FromLong(nBadTx));
647 PyList_Append(ferStatistics, PyInt_FromLong(nBadRx));
648 PyList_Append(ferStatistics, confRegAddresses);
649 PyList_Append(ferStatistics, confRegHistogram);
651 warning(
"SPI BER test finished!!!");
652 return ferStatistics;
668 major = (double)((rxversion>>12) & 0x0F);
669 minor = (double)((rxversion >>8) & 0x0F);
670 version_str =
itos(major) +
"." +
itos(minor);
671 version = atof( version_str.c_str() );
673 info(
"ICECAL Version: " +
ftos(version),
"ICECALv3::version");
684 return(rxData > 127);
691 unsigned int addr, rw, pumpRst, conf, regSel;
693 for(addr=0; addr<256; addr++)
696 pumpRst = (addr>>6) & 0x01;
697 conf = (addr>>5) & 0x01;
698 regSel = addr & 0x1F;
701 warning(
"R/!W="+
itos(rw)+
" PUMPrst="+
itos(pumpRst)+
" !CONF/STAT="+
itos(conf)+
" REGsel="+
itos(regSel)+
" ~ SPI(@=0x"+
itohs(addr)+
") = 0x"+
itohs(rxData),
"ICECALv3::spiAddressScan");
void info(std::string mymsg)
#define BXID_RESYNCH_ADDR
const int icecalMSBAddrCh[4]
virtual StatusCode write()
PyObject * getAnalogCh(int ch)
void setName(std::string name)
const int icecalMainAddr[4]
PyObject * spiFERTest(long nTest)
StatusCode dumpConfig(string configFile, PyObject *chipId)
StatusCode setAnalogCh(int ch, PyObject *)
virtual StatusCode read()
StatusCode setMainReg(PyObject *)
void setType(std::string type)
bool writeAsicParams(string fileName, PyObject *params)
void error(std::string mymsg)
void setId(unsigned char id)
void debug(std::string mymsg)
const int icecalLSBAddrCh[4]
int parseParameterList(string configFile, string paramName[64], int paramValue[64])
void spiWrite(U8 confRegAddr, U16 confRegData)
StatusCode setDelayLineCh(int ch, PyObject *)
std::string itohs(int value)
const int delayLineAddrCh[4]
StatusCode setSubAddress(U32 subAddress)
PyObject * getDelayLineCh(int ch)
virtual void addChild(Hierarchy *element)
PyObject * fillParams(string paramListRet[], int paramListLen, string paramName[64], int paramValue[64], int fileParamLen)
#define ICECAL_VERSION_ADDR
PyObject * loadConfig(string configFile)
#define CALIBRATION_FILE_VER
StatusCode setWordSize(IOdata::WordSize wordSize)
void defDataU8(unsigned long size)
U16 spiRead(U8 confRegAddr, U8 offsetAddr=128)
void warning(std::string mymsg)
bool spiWriteSafe(U8 confRegAddr, U16 confRegData)