ctb moench: feature to set digital io pin delay, changed print from unsuccessful to failed, maxpatternlength in server is inclusive

This commit is contained in:
maliakal_d 2019-03-01 10:45:01 +01:00
parent bb81613900
commit 35b1ad39f7
12 changed files with 173 additions and 32 deletions

View File

@ -506,12 +506,12 @@
/* Pin Delay 0 RW register */
#define OUTPUT_DELAY_0_REG (0x7C << MEM_MAP_SHIFT)
#define OUTPUT_DELAY_0_OTPT_STTNG_STEPS (25)
#define OUTPUT_DELAY_0_OTPT_STTNG_OFST (0) //t = OTPT_STTNG * 25 ps, max for Cyclone V = 775 ps
#define OUTPUT_DELAY_0_OTPT_STTNG_MSK (0x0000001F << OUTPUT_DELAY_0_OFST)
#define OUTPUT_DELAY_0_OTPT_STTNG_MSK (0x0000001F << OUTPUT_DELAY_0_OTPT_STTNG_OFST)
// 1: load dynamic output settings, 0: trigger start of dynamic output delay configuration pn falling edge of ODT (output delay trigger) bit
#define OUTPUT_DELAY_0_OTPT_TRGGR_OFST (31)
#define OUTPUT_DELAY_0_OTPT_TRGGR_MSK (0x00000001 << OUTPUT_DELAY_0_OFST)
#define OUTPUT_DELAY_0_OTPT_TRGGR_MSK (0x00000001 << OUTPUT_DELAY_0_OTPT_TRGGR_OFST)
#define OUTPUT_DELAY_0_OTPT_TRGGR_LD_VAL (1)
#define OUTPUT_DELAY_0_OTPT_TRGGR_STRT_VAL (0)

View File

@ -1761,9 +1761,9 @@ uint64_t writePatternClkControl(uint64_t word) {
uint64_t readPatternWord(int addr) {
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
if (addr < 0 || addr > MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. "
"Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH));
"Should be <= 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -1792,9 +1792,9 @@ uint64_t writePatternWord(int addr, uint64_t word) {
return readPatternWord(addr);
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
if (addr < 0 || addr > MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. "
"Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH));
"Should be <= 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -1820,9 +1820,9 @@ uint64_t writePatternWord(int addr, uint64_t word) {
int setPatternWaitAddress(int level, int addr) {
// error (handled in tcp)
if (addr >= MAX_PATTERN_LENGTH) {
if (addr > MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern - Wait Address. Invalid addr 0x%x. "
"Should be within 0x%x\n", addr, MAX_PATTERN_LENGTH));
"Should be <= 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -1905,7 +1905,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
if ((level != -1) &&
(*startAddr > MAX_PATTERN_LENGTH || *stopAddr > MAX_PATTERN_LENGTH)) {
FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
"Addr must be <= 0x%x\n",
level, *startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
@ -1913,7 +1913,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
else if ((level == -1) &&
(*startAddr > MAX_PATTERN_LENGTH || *stopAddr > MAX_PATTERN_LENGTH)) {
FILE_LOG(logERROR, ("Cannot set Pattern (Pattern Loop, complete pattern, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
"Addr must be <= 0x%x\n",
*startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
@ -2019,6 +2019,28 @@ int setLEDEnable(int enable) {
return (((~bus_r(addr)) & CONFIG_LED_DSBL_MSK) >> CONFIG_LED_DSBL_OFST);
}
void setDigitalIODelay(uint64_t pinMask, int delay) {
FILE_LOG(logINFO, ("Setings Digital IO Delay (pinMask:0x%llx, delay: %d ps)\n",
(long long unsigned int)pinMask, delay));
int delayunit = delay / OUTPUT_DELAY_0_OTPT_STTNG_STEPS;
FILE_LOG(logDEBUG1, ("delay unit: 0x%x (steps of 25ps)\n", delayunit));
// set pin mask
bus_w(PIN_DELAY_1_REG, pinMask);
uint32_t addr = OUTPUT_DELAY_0_REG;
// set delay
bus_w(addr, bus_r(addr) & (~OUTPUT_DELAY_0_OTPT_STTNG_MSK));
bus_w(addr, (bus_r(addr) | ((delayunit << OUTPUT_DELAY_0_OTPT_STTNG_OFST) & OUTPUT_DELAY_0_OTPT_STTNG_MSK)));
// load value
bus_w(addr, bus_r(addr) | OUTPUT_DELAY_0_OTPT_TRGGR_MSK);
// trigger configuration
bus_w(addr, bus_r(addr) & (~OUTPUT_DELAY_0_OTPT_TRGGR_MSK));
}
/* aquisition */

View File

@ -78,6 +78,9 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
/* Defines in the Firmware */
#define MAX_PATTERN_LENGTH (0xFFFF)
#define DIGITAL_IO_DELAY_MAXIMUM_PS ((OUTPUT_DELAY_0_OTPT_STTNG_MSK >> OUTPUT_DELAY_0_OTPT_STTNG_OFST) * OUTPUT_DELAY_0_OTPT_STTNG_STEPS)
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
#define WAIT_TIME_US_PLL (10 * 1000)
#define WAIT_TIME_US_STP_ACQ (100)

View File

@ -254,6 +254,7 @@ int setPatternWaitAddress(int level, int addr);
uint64_t setPatternWaitTime(int level, uint64_t t);
void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop);
int setLEDEnable(int enable);
void setDigitalIODelay(uint64_t pinMask, int delay);
#endif
// gotthard specific - image, pedestal

View File

@ -212,6 +212,7 @@ const char* getFunctionName(enum detFuncs func) {
case F_CHECK_VERSION: return "F_CHECK_VERSION";
case F_SOFTWARE_TRIGGER: return "F_SOFTWARE_TRIGGER";
case F_LED: return "F_LED";
case F_DIGITAL_IO_DELAY: return "F_DIGITAL_IO_DELAY";
default: return "Unknown Function";
}
@ -277,6 +278,7 @@ void function_table() {
flist[F_CHECK_VERSION] = &check_version;
flist[F_SOFTWARE_TRIGGER] = &software_trigger;
flist[F_LED] = &led;
flist[F_DIGITAL_IO_DELAY] = &digital_io_delay;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -2530,7 +2532,7 @@ int set_ctb_pattern(int file_des) {
// address for set word should be valid (if not -1 or -2, it goes to setword)
if (addr < -2 || addr > MAX_PATTERN_LENGTH) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Word, addr:0x%x). Addr must be less than 0x%x\n",
sprintf(mess, "Cannot set Pattern (Word, addr:0x%x). Addr must be <= 0x%x\n",
addr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
} else {
@ -2592,7 +2594,7 @@ int set_ctb_pattern(int file_des) {
else if ((loopLevel != -1) && (startAddr > MAX_PATTERN_LENGTH || stopAddr > MAX_PATTERN_LENGTH )) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Pattern Loop, level:%d, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
"Addr must be <= 0x%x\n",
loopLevel, startAddr, stopAddr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
}
@ -2601,7 +2603,7 @@ int set_ctb_pattern(int file_des) {
else if ((loopLevel == -1) && (startAddr > MAX_PATTERN_LENGTH || stopAddr > MAX_PATTERN_LENGTH)) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Pattern Loop, complete pattern, startaddr:0x%x, stopaddr:0x%x). "
"Addr must be less than 0x%x\n",
"Addr must be <= 0x%x\n",
startAddr, stopAddr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
}
@ -2641,7 +2643,7 @@ int set_ctb_pattern(int file_des) {
FILE_LOG(logERROR,(mess));
} else if (addr > MAX_PATTERN_LENGTH) {
ret = FAIL;
sprintf(mess, "Cannot set Pattern (Wait Address, addr:0x%x). Addr must be less than 0x%x\n",
sprintf(mess, "Cannot set Pattern (Wait Address, addr:0x%x). Addr must be <= 0x%x\n",
addr, MAX_PATTERN_LENGTH);
FILE_LOG(logERROR, (mess));
} else {
@ -3443,7 +3445,7 @@ int software_trigger(int file_des) {
sprintf(mess, "Could not send software trigger\n");
FILE_LOG(logERROR,(mess));
}
FILE_LOG(logDEBUG1, ("Software trigger ret: %d\n", ret));
FILE_LOG(logDEBUG1, ("Software trigger successful\n"));
}
#endif
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
@ -3475,3 +3477,35 @@ int led(int file_des) {
int digital_io_delay(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
uint64_t args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT64) < 0)
return printSocketReadError();
FILE_LOG(logDEBUG1, ("Digital IO Delay, pinMask: 0x%llx, delay:%d ps\n", args[0], (int)args[1]));
#if (!defined(MOENCHD)) && (!defined(CHIPTESTBOARDD))
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
int delay = (int)args[1];
if (delay < 0 || delay > DIGITAL_IO_DELAY_MAXIMUM_PS) {
ret = FAIL;
sprintf(mess, "Could not set digital IO delay. Delay maximum is %d ps\n", DIGITAL_IO_DELAY_MAXIMUM_PS);
FILE_LOG(logERROR,(mess));
} else {
setDigitalIODelay(args[0], delay);
FILE_LOG(logDEBUG1, ("Digital IO Delay successful\n"));
}
}
#endif
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
}

View File

@ -80,3 +80,4 @@ int storage_cell_start(int);
int check_version(int);
int software_trigger(int);
int led(int);
int digital_io_delay(int);

View File

@ -3606,6 +3606,17 @@ int multiSlsDetector::setLEDEnable(int enable, int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setDigitalIODelay(uint64_t pinMask, int delay, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setDigitalIODelay(pinMask, delay);
}
// multi
auto r = parallelCall(&slsDetector::setDigitalIODelay, pinMask, delay);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
int level) {

View File

@ -1743,6 +1743,15 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
int setLEDEnable(int enable = -1, int detPos = -1);
/**
* Set Digital IO Delay (Moench, CTB only)
* @param digital IO mask to select the pins
* @param delay delay in ps(1 bit=25ps, max of 775 ps)
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int setDigitalIODelay(uint64_t pinMask, int delay, int detPos = -1);
/**
* Loads the detector setup from file
* @param fname file to read from

View File

@ -5108,6 +5108,30 @@ int slsDetector::setLEDEnable(int enable) {
return retval;
}
int slsDetector::setDigitalIODelay(uint64_t pinMask, int delay) {
int fnum = F_DIGITAL_IO_DELAY;
int ret = FAIL;
uint64_t args[2] = {pinMask, (uint64_t)delay};
FILE_LOG(logDEBUG1) << "Sending Digital IO Delay, pin mask: " << std::hex << args[0]
<< ", delay: " << std::dec << args[1] << " ps";
if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) {
auto client = sls::ClientSocket(false, thisDetector->hostname, thisDetector->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0);
// handle ret
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE));
} else {
FILE_LOG(logDEBUG1) << "Digital IO Delay successful";
}
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
}
return ret;
}
slsDetectorDefs::sls_detector_module *slsDetector::interpolateTrim(
sls_detector_module *a, sls_detector_module *b,
const int energy, const int e1, const int e2, int tb) {

View File

@ -1603,6 +1603,14 @@ public:
*/
int setLEDEnable(int enable = -1);
/**
* Set Digital IO Delay (Moench, CTB only)
* @param digital IO mask to select the pins
* @param delay delay in ps(1 bit=25ps, max of 775 ps)
* @returns OK or FAIL
*/
int setDigitalIODelay(uint64_t pinMask, int delay);
private:
/**

View File

@ -191,7 +191,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
*/
/*! \page acquisition
- \b acquire blocking acquisition (like calling sls_detector_acquire). Starts receiver and detector, writes and processes the data, stops detector. Only get!
\c Returns (string)\c "acquire unsuccessful" if fails, else \c "Acquired (int)", where int is number of frames caught.
\c Returns (string)\c "acquire failed" if fails, else \c "Acquired (int)", where int is number of frames caught.
*/
descrToFuncMap[i].m_pFuncName = "acquire"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAcquire;
@ -392,14 +392,14 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
/* fpga */
/*! \page config
- <b>programfpga [file]</b> programs the FPGA with file f (with .pof extension). Used for JUNGFRAU only. Only put! \c Returns \c ("successful", "unsuccessful")
- <b>programfpga [file]</b> programs the FPGA with file f (with .pof extension). Used for JUNGFRAU only. Only put! \c Returns \c ("successful", "failed")
*/
descrToFuncMap[i].m_pFuncName = "programfpga";
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced;
++i;
/*! \page config
- <b>resetfpga [f]</b> resets FPGA, where f can be any value. Used for JUNGFRAU only. Only put! \c Returns \c ("successful", "unsuccessful")
- <b>resetfpga [f]</b> resets FPGA, where f can be any value. Used for JUNGFRAU only. Only put! \c Returns \c ("successful", "failed")
*/
descrToFuncMap[i].m_pFuncName = "resetfpga";
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced;
@ -425,6 +425,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced;
++i;
/*! \page config
- <b>diodelay [i] [v]</b> sets the delay for the digital IO pins selected by mask i and delay set by v. mask is upto 64 bits in hex, delay is a max is 775ps, and set in steps of 25 ps. Used for MOENCH/CTB only. Cannot get. \c Returns \c ("successful", failed")
*/
descrToFuncMap[i].m_pFuncName = "diodelay";
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced;
++i;
/*! \page config
- <b>auto_comp_disable i </b> Currently not implemented. this mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). 1 enables mode, 0 disables mode. By default, mode is disabled (comparator is enabled throughout). (JUNGFRAU only). \c Returns \c (int)
*/
@ -433,21 +440,21 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
++i;
/*! \page config
- <b>pulse [n] [x] [y]</b> pulses pixel at coordinates (x,y) n number of times. Used in EIGER only. Only put! \c Returns \c ("successful", "unsuccessful")
- <b>pulse [n] [x] [y]</b> pulses pixel at coordinates (x,y) n number of times. Used in EIGER only. Only put! \c Returns \c ("successful", "failed")
*/
descrToFuncMap[i].m_pFuncName = "pulse"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPulse;
++i;
/*! \page config
- <b>pulsenmove [n] [x] [y]</b> pulses pixel n number of times and moves relatively by x value (x axis) and y value(y axis). Used in EIGER only. Only put! \c Returns \c ("successful", "unsuccessful")
- <b>pulsenmove [n] [x] [y]</b> pulses pixel n number of times and moves relatively by x value (x axis) and y value(y axis). Used in EIGER only. Only put! \c Returns \c ("successful", "failed")
*/
descrToFuncMap[i].m_pFuncName = "pulsenmove"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPulse;
++i;
/*! \page config
- <b>pulsechip [n]</b>pulses chip n number of times, while n=-1 will reset it to normal mode. Used in EIGER only. Only put! \c Returns \c ("successful", "unsuccessful")
- <b>pulsechip [n]</b>pulses chip n number of times, while n=-1 will reset it to normal mode. Used in EIGER only. Only put! \c Returns \c ("successful", "failed")
*/
descrToFuncMap[i].m_pFuncName = "pulsechip"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPulse;
@ -2054,11 +2061,11 @@ std::string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action, i
}
if (!myDet->getNumberOfDetectors()) {
cprintf(RED, "Error: This shared memory has no detectors added. Aborting.\n");
return std::string("acquire unsuccessful");
return std::string("acquire failed");
}
if (detPos >= 0) {
cprintf(RED, "Error: Individual detectors not allowed for readout. Aborting.\n");
return std::string("acquire unsuccessful");
return std::string("acquire failed");
}
myDet->setOnline(ONLINE_FLAG, detPos);
@ -2067,7 +2074,7 @@ std::string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action, i
if (myDet->acquire() == FAIL)
return std::string("acquire unsuccessful");
return std::string("acquire failed");
if (r_online) {
char answer[100];
sprintf(answer, "\nAcquired %d", myDet->getFramesCaughtByReceiver(detPos));
@ -3380,7 +3387,7 @@ std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action,
if (ret == OK)
return sval;
else
return std::string("not successful");
return std::string("failed");
}
return myDet->getSettingsFile(detPos);
} else if (cmd == "trimval") {
@ -4592,7 +4599,7 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action,
myDet->setOnline(ONLINE_FLAG, detPos);
if (myDet->programFPGA(sval, detPos) == OK)
return std::string("successful");
return std::string("unsuccessful");
return std::string("failed");
}
else if (cmd == "resetfpga") {
@ -4604,7 +4611,7 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action,
myDet->setOnline(ONLINE_FLAG, detPos);
if (myDet->resetFPGA(detPos) == OK)
return std::string("successful");
return std::string("unsuccessful");
return std::string("failed");
}
else if (cmd == "powerchip") {
@ -4631,6 +4638,25 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action,
return std::to_string(myDet->setLEDEnable(-1, detPos));
}
else if (cmd == "diodelay") {
if (action == GET_ACTION) {
return std::string("Cannot get");
}
myDet->setOnline(ONLINE_FLAG, detPos);
uint64_t pinMask = -1;
if (!sscanf(args[1], "%lx", &pinMask))
return std::string("could not scan diodelay pin mask(in hex) " + std::string(args[1]));
int delay = -1;
if (!sscanf(args[2], "%d", &delay))
return std::string("could not scan diodelay delay " + std::string(args[2]));
int retval = myDet->setDigitalIODelay(pinMask, delay, detPos);
if (retval == -1)
return std::to_string(-1);
return std::string((retval == OK) ? "successful" : "failed");
}
else if (cmd == "auto_comp_disable") {
char ans[100];
myDet->setOnline(ONLINE_FLAG, detPos);
@ -4658,6 +4684,7 @@ std::string slsDetectorCommand::helpAdvanced(int action) {
os << "resetfpga f \t resets fpga, f can be any value" << std::endl;
os << "led s \t sets led status (0 off, 1 on)" << std::endl;
os << "diodelay m v \tsets the delay for the digital IO pins selected by mask m and delay set by v. mask is upto 64 bits in hex, delay max is 775ps, and set in steps of 25 ps. Used for MOENCH/CTB only." << std::endl;
os << "powerchip i \t powers on or off the chip. i = 1 for on, i = 0 for off" << std::endl;
os << "auto_comp_disable i \t Currently not implemented. this mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). 1 enables mode, 0 disables mode. By default, mode is disabled (comparator is enabled throughout). (JUNGFRAU only). " << std::endl;
}
@ -4778,10 +4805,10 @@ std::string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action,
if (action == GET_ACTION)
return std::string("cannot get");
else {
if (myDet->resetFramesCaught(detPos) == FAIL)
strcpy(answer, "failed");
else
if (myDet->resetFramesCaught(detPos) == OK)
strcpy(answer, "successful");
else
strcpy(answer, "failed");
return std::string(answer);
}
}
@ -5462,7 +5489,7 @@ std::string slsDetectorCommand::cmdPulse(int narg, char *args[], int action, int
if (retval == OK)
return std::string(" successful");
else
return std::string(" unsuccessful");
return std::string(" failed");
}

View File

@ -69,6 +69,7 @@ enum detFuncs{
F_CHECK_VERSION,/** < check version compatibility */
F_SOFTWARE_TRIGGER,/** < software trigger */
F_LED, /** < switch on/off led */
F_DIGITAL_IO_DELAY, /** < digital IO delay */
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 128, /**< detector function should not exceed this (detector server should not compile anyway) */