Merge pull request #267 from slsdetectorgroup/jungfrauchip

Jungfrau features: 1. chip version
This commit is contained in:
Dhanya Thattil 2021-07-27 17:56:10 +02:00 committed by GitHub
commit 0eca60c791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 255 additions and 27 deletions

View File

@ -1992,6 +1992,20 @@ class Detector(CppDetectorApi):
Jungfrau specific
"""
@property
@element
def chipversion(self):
"""
[Jungfrau] Chip version of module. Can be 1.0 or 1.1.
Example
-------
>>> d.chipversion
'1.0'
"""
return self.getChipVersion()
@property
@element
def auto_comp_disable(self):

View File

@ -947,6 +947,10 @@ void init_det(py::module &m) {
(void (Detector::*)(sls::Positions)) &
Detector::resetTemperatureEvent,
py::arg() = Positions{})
.def("getChipVersion",
(Result<double>(Detector::*)(sls::Positions) const) &
Detector::getChipVersion,
py::arg() = Positions{})
.def("getAutoCompDisable",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getAutoCompDisable,

View File

@ -1106,7 +1106,7 @@ int Feb_Control_SendSoftwareTrigger() {
LOG(logERROR, ("Could not give software trigger\n"));
return 0;
}
LOG(logINFO, ("Software Internal Trigger Sent!\n"));
LOG(logDEBUG1, ("Software Internal Trigger Sent!\n"));
return 1;
}
@ -1129,7 +1129,7 @@ int Feb_Control_SoftwareTrigger(int block) {
// wait for next trigger ready
if (block) {
LOG(logINFO, ("Blocking Software Trigger\n"));
LOG(logDEBUG1, ("Blocking Software Trigger\n"));
int readyForTrigger = 0;
if (!Feb_Control_IsReadyForTrigger(&readyForTrigger)) {
LOG(logERROR, ("Could not read FEB_REG_STATUS reg after giving "
@ -1138,6 +1138,15 @@ int Feb_Control_SoftwareTrigger(int block) {
}
while (!readyForTrigger) {
// end of acquisition (cannot monitor readyForTrigger)
int status = Feb_Control_AcquisitionInProgress();
if (status == STATUS_ERROR) {
LOG(logERROR, ("Status: ERROR reading DAQ status register\n"));
return 0;
} else if (status == STATUS_IDLE) {
break;
}
usleep(5000);
if (!Feb_Control_IsReadyForTrigger(&readyForTrigger)) {
LOG(logERROR, ("Could not read FEB_REG_STATUS reg after "
@ -1145,8 +1154,10 @@ int Feb_Control_SoftwareTrigger(int block) {
return 0;
}
}
LOG(logINFO, ("Done waiting (wait for trigger)!\n"));
LOG(logDEBUG2, ("Done waiting (wait for trigger)!\n"));
}
LOG(logINFO, ("%s Software Trigger %s\n", (block ? "Blocking" : "Non blocking"), (block ? "Acquired" : "Sent")));
fflush(stdout);
}
return 1;

View File

@ -434,8 +434,9 @@ int readConfigFile() {
master = -1;
top = -1;
char fname[128];
if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) {
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
return FAIL;
}

View File

@ -530,8 +530,9 @@ int readConfigFile() {
usleep(INITIAL_STARTUP_WAIT);
char fname[128];
if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) {
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
return FAIL;
}
@ -1833,15 +1834,23 @@ int checkDetectorType() {
int type = atoi(buffer);
if (type > TYPE_NO_MODULE_STARTING_VAL) {
LOG(logERROR,
("No Module attached! Expected %d for Gotthard2, got %d\n",
TYPE_GOTTHARD2_MODULE_VAL, type));
("No Module attached! Expected %d, %d or %d for Gotthard2, got %d\n",
TYPE_GOTTHARD2_MODULE_VAL,
TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL,
TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL,
type));
return -2;
}
if (abs(type - TYPE_GOTTHARD2_MODULE_VAL) > TYPE_TOLERANCE) {
if ((abs(type - TYPE_GOTTHARD2_MODULE_VAL) > TYPE_TOLERANCE) &&
(abs(type - TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL) > TYPE_TOLERANCE) &&
(abs(type - TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL) > TYPE_TOLERANCE)) {
LOG(logERROR,
("Wrong Module attached! Expected %d for Gotthard2, got %d\n",
TYPE_GOTTHARD2_MODULE_VAL, type));
("Wrong Module attached! Expected %d, %d or %d for Gotthard2, got %d\n",
TYPE_GOTTHARD2_MODULE_VAL,
TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL,
TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL,
type));
return FAIL;
}
return OK;

View File

@ -26,7 +26,10 @@
#define ADU_MAX_BITS (12)
#define MAX_FRAMES_IN_BURST_MODE (2720)
#define TYPE_GOTTHARD2_MODULE_VAL (536)
#define TYPE_TOLERANCE (10)
#define TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL (683)
#define TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL (704)
#define TYPE_GOTTHARD2_MODULE_VAL (536)
#define TYPE_TOLERANCE (5)
#define TYPE_NO_MODULE_STARTING_VAL (800)
#define INITIAL_STARTUP_WAIT (1 * 1000 * 1000)

View File

@ -588,8 +588,9 @@ void setGbitReadout() {
}
int readConfigFile() {
char fname[128];
if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) {
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
return FAIL;
}

View File

@ -36,4 +36,6 @@ set_target_properties(jungfrauDetectorServer_virtual PROPERTIES
install(TARGETS jungfrauDetectorServer_virtual
EXPORT "${TARGETS_EXPORT_NAME}"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
)
configure_file(config_jungfrau.txt ${CMAKE_BINARY_DIR}/bin/config_jungfrau.txt COPYONLY)

View File

@ -32,6 +32,7 @@ $(PROGS): $(OBJS)
mkdir -p $(DESTDIR)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
cp config_jungfrau.txt $(DESTDIR)
rm *.gdb
rm $(main_src)*.o

View File

@ -0,0 +1,4 @@
#chip version version (multiplied by 10)
chipversion 11

View File

@ -45,6 +45,7 @@ int highvoltage = 0;
int dacValues[NDAC] = {};
int32_t clkPhase[NUM_CLOCKS] = {};
int detPos[4] = {};
int chipVersion = 10; // (1.0)
int isInitCheckDone() { return initCheckDone; }
@ -101,6 +102,7 @@ void basictests() {
if (fwversion >= MIN_REQRD_VRSN_T_RD_API)
sw_fw_apiversion = getFirmwareAPIVersion();
LOG(logINFOBLUE,
("************ Jungfrau Server *********************\n"
"Hardware Version:\t\t 0x%x\n"
@ -283,12 +285,17 @@ u_int16_t getHardwareSerialNumber() {
// is board 1.0?, with value 2 (resistor network)
int isHardwareVersion2() {
#ifdef VIRTUAL
return 0;
#endif
return (((bus_r(MOD_SERIAL_NUM_REG) & HARDWARE_VERSION_NUM_MSK) ==
HARDWARE_VERSION_2_VAL)
? 1
: 0);
}
int getChipVersion() { return chipVersion; }
u_int32_t getDetectorNumber() {
#ifdef VIRTUAL
return 0;
@ -383,6 +390,11 @@ void setupDetector() {
sharedMemory_setStatus(IDLE);
#endif
// get chip version
if (readConfigFile() == FAIL) {
return;
}
ALTERA_PLL_ResetPLL();
resetCore();
resetPeripheral();
@ -468,6 +480,127 @@ int setDefaultDacs() {
return ret;
}
int readConfigFile() {
if (initError == FAIL) {
return initError;
}
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
return FAIL;
}
// open config file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
sprintf(initErrorMessage,
"Could not open on-board detector server config file [%s].\n",
CONFIG_FILE);
initError = FAIL;
LOG(logERROR, ("%s\n\n", initErrorMessage));
return FAIL;
}
LOG(logINFOBLUE, ("Reading config file %s\n", CONFIG_FILE));
// Initialization
const size_t LZ = 256;
char line[LZ];
memset(line, 0, LZ);
char command[LZ];
// keep reading a line
while (fgets(line, LZ, fd)) {
// ignore comments
if (line[0] == '#') {
LOG(logDEBUG1, ("Ignoring Comment\n"));
continue;
}
// ignore empty lines
if (strlen(line) <= 1) {
LOG(logDEBUG1, ("Ignoring Empty line\n"));
continue;
}
// removing leading spaces
if (line[0] == ' ' || line[0] == '\t') {
int len = strlen(line);
// find first valid character
int i = 0;
for (i = 0; i < len; ++i) {
if (line[i] != ' ' && line[i] != '\t') {
break;
}
}
// ignore the line full of spaces (last char \n)
if (i >= len - 1) {
LOG(logDEBUG1, ("Ignoring line full of spaces\n"));
continue;
}
// copying only valid char
char temp[LZ];
memset(temp, 0, LZ);
memcpy(temp, line + i, strlen(line) - i);
memset(line, 0, LZ);
memcpy(line, temp, strlen(temp));
LOG(logDEBUG1, ("Removing leading spaces.\n"));
}
LOG(logDEBUG1, ("Command to process: (size:%d) %.*s\n", strlen(line),
strlen(line) - 1, line));
memset(command, 0, LZ);
// chipversion command
if (!strncmp(line, "chipversion", strlen("chipversion"))) {
int version = 0;
// cannot scan values
if (sscanf(line, "%s %d", command, &version) != 2) {
sprintf(
initErrorMessage,
"Could not scan chipversion commands from on-board server "
"config file. Line:[%s].\n",
line);
break;
}
// validations
if (version != 10 && version != 11) {
sprintf(initErrorMessage,
"Could not set chip version from on-board server "
"config file. Invalid chip version %d. Line:[%s].\n",
version, line);
break;
}
// validations
chipVersion = version;
LOG(logINFOBLUE, ("Chip Version: v%.01f\n", chipVersion / 10.0));
// version 1.1 and HW 1.0 (version reg value = 2) is incompatible
if (chipVersion == 11 && isHardwareVersion2()) {
strcpy(initErrorMessage,
"Chip version 1.1 (from on-board config file) is incompatible with old board (v1.0). Please update board or correct on-board config file.\n");
break;
}
}
memset(line, 0, LZ);
}
fclose(fd);
if (strlen(initErrorMessage)) {
initError = FAIL;
LOG(logERROR, ("%s\n\n", initErrorMessage));
} else {
LOG(logINFOBLUE, ("Successfully read config file\n"));
}
return initError;
}
/* firmware functions (resets) */
void cleanFifos() {

View File

@ -3,8 +3,8 @@
#include "sls/sls_detector_defs.h"
#define MIN_REQRD_VRSN_T_RD_API 0x171220
#define REQRD_FRMWRE_VRSN_BOARD2 0x210218 // 1.0 pcb
#define REQRD_FRMWRE_VRSN 0x200721 // 2.0 pcb
#define REQRD_FRMWRE_VRSN_BOARD2 0x210621 // 1.0 pcb
#define REQRD_FRMWRE_VRSN 0x210622 // 2.0 pcb
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
@ -77,6 +77,7 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS };
#define CLK_SYNC (20) // MHz
#define ADC_CLK_INDEX (1)
#define DBIT_CLK_INDEX (0)
#define CONFIG_FILE ("config_jungfrau.txt")
/** Default Parameters */
#define DEFAULT_NUM_FRAMES (100 * 1000 * 1000)

View File

@ -21,7 +21,7 @@
#define TYPE_FILE_NAME ("/etc/devlinks/type")
#define DAC_MAX_MV (2048)
#define TYPE_MYTHEN3_MODULE_VAL (93)
#define TYPE_TOLERANCE (10)
#define TYPE_TOLERANCE (5)
#define TYPE_NO_MODULE_STARTING_VAL (800)
#define MAX_EXT_SIGNALS (8)

View File

@ -87,6 +87,7 @@ u_int16_t getHardwareSerialNumber();
#endif
#ifdef JUNGFRAUD
int isHardwareVersion2();
int getChipVersion();
#endif
#if defined(EIGERD) || defined(MYTHEN3D)
void readDetectorNumber();
@ -122,7 +123,7 @@ int setDefaultDacs();
void setASICDefaults();
void setADIFDefaults();
#endif
#if defined(GOTTHARD2D) || defined(EIGERD)
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD)
int readConfigFile();
#endif
#ifdef EIGERD

View File

@ -253,3 +253,4 @@ int get_veto_stream(int);
int set_veto_stream(int);
int get_veto_algorithm(int);
int set_veto_algorithm(int);
int get_chip_version(int);

View File

@ -379,6 +379,7 @@ void function_table() {
flist[F_SET_VETO_STREAM] = &set_veto_stream;
flist[F_GET_VETO_ALGORITHM] = &get_veto_algorithm;
flist[F_SET_VETO_ALGORITHM] = &set_veto_algorithm;
flist[F_GET_CHIP_VERSION] = &get_chip_version;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -8432,4 +8433,17 @@ int set_veto_algorithm(int file_des) {
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_chip_version(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
#ifndef JUNGFRAUD
functionNotImplemented();
#else
retval = getChipVersion();
#endif
LOG(logDEBUG1, ("chip version retval: %d\n", retval));
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}

View File

@ -1081,6 +1081,9 @@ class Detector {
* *
* ************************************************/
/** [Jungfrau] */
Result<double> getChipVersion(Positions pos = {}) const;
/** [Jungfrau] */
Result<int> getThresholdTemperature(Positions pos = {}) const;

View File

@ -918,6 +918,7 @@ class CmdProxy {
{"datastream", &CmdProxy::DataStream},
/* Jungfrau Specific */
{"chipversion", &CmdProxy::chipversion},
{"temp_threshold", &CmdProxy::temp_threshold},
{"temp_control", &CmdProxy::temp_control},
{"temp_event", &CmdProxy::TemperatureEvent},
@ -1812,6 +1813,9 @@ class CmdProxy {
/* Jungfrau Specific */
GET_COMMAND(chipversion, getChipVersion,
"\n\t[Jungfrau] Returns chip version. Can be 1.0 or 1.1");
INTEGER_COMMAND_VEC_ID(
temp_threshold, getThresholdTemperature, setThresholdTemperature,
StringTo<int>,

View File

@ -1398,6 +1398,9 @@ void Detector::setDataStream(const defs::portPosition port, const bool enable,
}
// Jungfrau Specific
Result<double> Detector::getChipVersion(Positions pos) const {
return pimpl->Parallel(&Module::getChipVersion, pos);
}
Result<int> Detector::getThresholdTemperature(Positions pos) const {
return pimpl->Parallel(&Module::getThresholdTemperature, pos);

View File

@ -1522,6 +1522,9 @@ void Module::setDataStream(const portPosition port, const bool enable) {
}
// Jungfrau Specific
double Module::getChipVersion() const {
return (sendToDetector<int>(F_GET_CHIP_VERSION)) / 10.00;
}
int Module::getThresholdTemperature() const {
auto retval = sendToDetectorStop<int>(F_THRESHOLD_TEMP, GET_FLAG);

View File

@ -351,6 +351,7 @@ class Module : public virtual slsDetectorDefs {
* Jungfrau Specific *
* *
* ************************************************/
double getChipVersion() const;
int getThresholdTemperature() const;
void setThresholdTemperature(int val);
bool getTemperatureControl() const;

View File

@ -190,6 +190,18 @@ TEST_CASE("temp_threshold", "[.cmd]") {
}
}
TEST_CASE("chipversion", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
REQUIRE_NOTHROW(proxy.Call("chipversion", {}, -1, GET));
} else {
REQUIRE_THROWS(proxy.Call("chipversion", {}, -1, GET));
}
REQUIRE_THROWS(proxy.Call("chipversion", {"0"}, -1, PUT));
}
TEST_CASE("temp_control", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);

View File

@ -230,6 +230,7 @@ enum detFuncs {
F_SET_VETO_STREAM,
F_GET_VETO_ALGORITHM,
F_SET_VETO_ALGORITHM,
F_GET_CHIP_VERSION,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -566,6 +567,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_VETO_STREAM: return "F_SET_VETO_STREAM";
case F_GET_VETO_ALGORITHM: return "F_GET_VETO_ALGORITHM";
case F_SET_VETO_ALGORITHM: return "F_SET_VETO_ALGORITHM";
case F_GET_CHIP_VERSION: return "F_GET_CHIP_VERSION";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";

View File

@ -3,10 +3,10 @@
#define APILIB 0x210225
#define APIRECEIVER 0x210225
#define APIGUI 0x210225
#define APICTB 0x210722
#define APIGOTTHARD 0x210722
#define APIGOTTHARD2 0x210722
#define APIJUNGFRAU 0x210722
#define APIMYTHEN3 0x210722
#define APIMOENCH 0x210722
#define APIEIGER 0x210722
#define APICTB 0x210727
#define APIGOTTHARD 0x210727
#define APIGOTTHARD2 0x210727
#define APIMYTHEN3 0x210727
#define APIMOENCH 0x210727
#define APIEIGER 0x210727
#define APIJUNGFRAU 0x210727