Merge pull request #95 from slsdetectorgroup/trim

Trim
This commit is contained in:
Dhanya Thattil 2020-05-08 13:39:42 +02:00 committed by GitHub
commit 1dfac6ae6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 645 additions and 344 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <stdlib.h>
#include "LocalLinkInterface.h" #include "LocalLinkInterface.h"
#include "slsDetectorServer_defs.h" #include "slsDetectorServer_defs.h"

View File

@ -217,9 +217,8 @@ int testBus() {
int ret = OK; int ret = OK;
u_int32_t addr = DTA_OFFSET_REG; u_int32_t addr = DTA_OFFSET_REG;
u_int32_t times = 1000 * 1000; u_int32_t times = 1000 * 1000;
u_int32_t i = 0;
for (i = 0; i < times; ++i) { for (u_int32_t i = 0; i < times; ++i) {
bus_w(addr, i * 100); bus_w(addr, i * 100);
if (i * 100 != bus_r(addr)) { if (i * 100 != bus_r(addr)) {
LOG(logERROR, LOG(logERROR,
@ -375,26 +374,23 @@ void setupDetector() {
delayReg = 0; delayReg = 0;
numBurstsReg = 1; numBurstsReg = 1;
burstPeriodReg = 0; burstPeriodReg = 0;
{ for (int i = 0; i < NUM_CLOCKS; ++i) {
int i, j; clkPhase[i] = 0;
for (i = 0; i < NUM_CLOCKS; ++i) { }
clkPhase[i] = 0; for (int i = 0; i < NDAC; ++i) {
dacValues[i] = 0;
}
for (int i = 0; i < ONCHIP_NDAC; ++i) {
for (int j = 0; j < NCHIP; ++j) {
onChipdacValues[i][j] = -1;
} }
for (i = 0; i < NDAC; ++i) { }
dacValues[i] = 0; for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NCHAN; ++j) {
vetoReference[i][j] = 0;
} }
for (i = 0; i < ONCHIP_NDAC; ++i) { for (int j = 0; j < NADC; ++j) {
for (j = 0; j < NCHIP; ++j) { adcConfiguration[i][j] = 0;
onChipdacValues[i][j] = -1;
}
}
for (i = 0; i < NCHIP; ++i) {
for (j = 0; j < NCHAN; ++j) {
vetoReference[i][j] = 0;
}
for (j = 0; j < NADC; ++j) {
adcConfiguration[i][j] = 0;
}
} }
} }
#ifdef VIRTUAL #ifdef VIRTUAL
@ -647,9 +643,8 @@ int readConfigFile() {
adcmax = iadc + 1; adcmax = iadc + 1;
} }
int i, j; for (int i = chipmin; i < chipmax; ++i) {
for (i = chipmin; i < chipmax; ++i) { for (int j = adcmin; j < adcmax; ++j) {
for (j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value; adcConfiguration[i][j] = (uint8_t)value;
++nadcRead; ++nadcRead;
} }
@ -776,13 +771,10 @@ int readConfigFile() {
nadcRead, NADC * NCHIP); nadcRead, NADC * NCHIP);
} }
} }
{ for (int i = 0; i < NCHIP; ++i) {
int i = 0, j = 0; for (int j = 0; j < NADC; ++j) {
for (i = 0; i < NCHIP; ++i) { LOG(logDEBUG2,
for (j = 0; j < NADC; ++j) { ("adc read %d %d: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
LOG(logDEBUG2, ("adc read %d %d: 0x%02hhx\n", i, j,
adcConfiguration[i][j]));
}
} }
} }
@ -1143,8 +1135,7 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val) {
} }
// all chips // all chips
if (chipIndex == -1) { if (chipIndex == -1) {
int ichip = 0; for (int ichip = 0; ichip < NCHIP; ++ichip) {
for (ichip = 0; ichip < NCHIP; ++ichip) {
onChipdacValues[ind][ichip] = val; onChipdacValues[ind][ichip] = val;
} }
} }
@ -1160,9 +1151,8 @@ int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex) {
// all chips // all chips
if (chipIndex == -1) { if (chipIndex == -1) {
int retval = onChipdacValues[ind][0]; int retval = onChipdacValues[ind][0];
int ichip = 0;
// check if same value for remaining chips // check if same value for remaining chips
for (ichip = 1; ichip < NCHIP; ++ichip) { for (int ichip = 1; ichip < NCHIP; ++ichip) {
if (onChipdacValues[ind][ichip] != retval) { if (onChipdacValues[ind][ichip] != retval) {
return -1; return -1;
} }
@ -1641,8 +1631,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
// Remembering old phases in degrees // Remembering old phases in degrees
int oldPhases[NUM_CLOCKS]; int oldPhases[NUM_CLOCKS];
{ {
int i = 0; for (int i = 0; i < NUM_CLOCKS; ++i) {
for (i = 0; i < NUM_CLOCKS; ++i) {
oldPhases[i] = getPhase(i, 1); oldPhases[i] = getPhase(i, 1);
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n", LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
clock_names[ind], ind, oldPhases[i])); clock_names[ind], ind, oldPhases[i]));
@ -1673,16 +1662,13 @@ int setClockDivider(enum CLKINDEX ind, int val) {
} }
// set the phase in degrees (reset by pll) // set the phase in degrees (reset by pll)
{ for (int i = 0; i < NUM_CLOCKS; ++i) {
int i = 0; int currPhaseDeg = getPhase(i, 1);
for (i = 0; i < NUM_CLOCKS; ++i) { if (oldPhases[i] != currPhaseDeg) {
int currPhaseDeg = getPhase(i, 1); LOG(logINFO,
if (oldPhases[i] != currPhaseDeg) { ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
LOG(logINFO, clock_names[i], i, currPhaseDeg, oldPhases[i]));
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", setPhase(i, oldPhases[i], 1);
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
} }
} }
return OK; return OK;
@ -1711,8 +1697,8 @@ int setInjectChannel(int offset, int increment) {
char buffer[17]; char buffer[17];
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
int startCh = 4; // 4 due to padding int startCh = 4; // 4 due to padding
int ich = 0; for (int ich = startCh + offset; ich < startCh + NCHAN;
for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) { ich = ich + increment) {
int byteIndex = ich / 8; int byteIndex = ich / 8;
int bitIndex = ich % 8; int bitIndex = ich % 8;
buffer[byteIndex] |= (1 << (8 - 1 - bitIndex)); buffer[byteIndex] |= (1 << (8 - 1 - bitIndex));
@ -1741,8 +1727,7 @@ int setVetoReference(int gainIndex, int value) {
gainIndex, value)); gainIndex, value));
int vals[NCHAN]; int vals[NCHAN];
memset(vals, 0, sizeof(vals)); memset(vals, 0, sizeof(vals));
int ich = 0; for (int ich = 0; ich < NCHAN; ++ich) {
for (ich = 0; ich < NCHAN; ++ich) {
vals[ich] = value; vals[ich] = value;
} }
return setVetoPhoton(-1, gainIndex, vals); return setVetoPhoton(-1, gainIndex, vals);
@ -1770,8 +1755,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
return FAIL; return FAIL;
} }
LOG(logDEBUG2, ("Adding gain bits\n")); LOG(logDEBUG2, ("Adding gain bits\n"));
int i = 0; for (int i = 0; i < NCHAN; ++i) {
for (i = 0; i < NCHAN; ++i) {
values[i] |= gainValue; values[i] |= gainValue;
LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i])); LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i]));
} }
@ -1787,8 +1771,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
uint8_t commandBytes[lenTotalBits]; uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes)); memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes int offset = padding; // bit offset for commandbytes
int ich = 0; for (int ich = 0; ich < NCHAN; ++ich) {
for (ich = 0; ich < NCHAN; ++ich) {
// loop through all bits in a value // loop through all bits in a value
int iBit = 0; int iBit = 0;
for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) { for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) {
@ -1803,10 +1786,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
memset(buffer, 0, len); memset(buffer, 0, len);
offset = 0; offset = 0;
// loop through buffer elements // loop through buffer elements
for (ich = 0; ich < len; ++ich) { for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element // loop through each bit in buffer element
int iBit = 0; for (int iBit = 0; iBit < 8; ++iBit) {
for (iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit)); buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
} }
} }
@ -1820,10 +1802,8 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
// all chips // all chips
if (chipIndex == -1) { if (chipIndex == -1) {
int ichip = 0; for (int ichan = 0; ichan < NCHAN; ++ichan) {
int ichan = 0; for (int ichip = 0; ichip < NCHIP; ++ichip) {
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (ichip = 0; ichip < NCHIP; ++ichip) {
vetoReference[ichip][ichan] = values[ichan]; vetoReference[ichip][ichan] = values[ichan];
} }
} }
@ -1831,8 +1811,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
// specific chip // specific chip
else { else {
int ichan = 0; for (int ichan = 0; ichan < NCHAN; ++ichan) {
for (ichan = 0; ichan < NCHAN; ++ichan) {
vetoReference[chipIndex][chipIndex] = values[ichan]; vetoReference[chipIndex][chipIndex] = values[ichan];
; ;
} }
@ -1842,10 +1821,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
int getVetoPhoton(int chipIndex, int *retvals) { int getVetoPhoton(int chipIndex, int *retvals) {
if (chipIndex == -1) { if (chipIndex == -1) {
int i = 0, j = 0; for (int i = 0; i < NCHAN; ++i) {
for (i = 0; i < NCHAN; ++i) {
int val = vetoReference[0][i]; int val = vetoReference[0][i];
for (j = 1; j < NCHIP; ++j) { for (int j = 1; j < NCHIP; ++j) {
if (vetoReference[j][i] != val) { if (vetoReference[j][i] != val) {
LOG(logERROR, LOG(logERROR,
("Get vet photon fail for chipIndex:%d. Different " ("Get vet photon fail for chipIndex:%d. Different "
@ -1876,14 +1854,11 @@ int configureSingleADCDriver(int chipIndex) {
memcpy(values, adcConfiguration + ind * NADC, NADC); memcpy(values, adcConfiguration + ind * NADC, NADC);
// change adc values if continuous mode // change adc values if continuous mode
{ for (int i = 0; i < NADC; ++i) {
int i = 0; if (burstMode == BURST_OFF) {
for (i = 0; i < NADC; ++i) { values[i] |= ASIC_CONTINUOUS_MODE_MSK;
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
} }
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
} }
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7 const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
@ -1896,11 +1871,9 @@ int configureSingleADCDriver(int chipIndex) {
uint8_t commandBytes[lenTotalBits]; uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes)); memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes int offset = padding; // bit offset for commandbytes
int ich = 0; for (int ich = 0; ich < NADC; ++ich) {
for (ich = 0; ich < NADC; ++ich) {
// loop through all bits in a value // loop through all bits in a value
int iBit = 0; for (int iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
for (iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
commandBytes[offset++] = commandBytes[offset++] =
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1); ((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
} }
@ -1912,10 +1885,9 @@ int configureSingleADCDriver(int chipIndex) {
memset(buffer, 0, len); memset(buffer, 0, len);
offset = 0; offset = 0;
// loop through buffer elements // loop through buffer elements
for (ich = 0; ich < len; ++ich) { for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element // loop through each bit in buffer element
int iBit = 0; for (int iBit = 0; iBit < 8; ++iBit) {
for (iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit)); buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
} }
} }
@ -1934,23 +1906,19 @@ int configureADC() {
LOG(logINFO, ("Configuring ADC \n")); LOG(logINFO, ("Configuring ADC \n"));
int equal = 1; int equal = 1;
{ for (int i = 0; i < NADC; ++i) {
int i = 0, j = 0; int val = adcConfiguration[0][i];
for (i = 0; i < NADC; ++i) { for (int j = 1; j < NCHIP; ++j) {
int val = adcConfiguration[0][i]; if (adcConfiguration[j][i] != val) {
for (j = 1; j < NCHIP; ++j) { equal = 0;
if (adcConfiguration[j][i] != val) { break;
equal = 0;
break;
}
} }
} }
} }
if (equal) { if (equal) {
return configureSingleADCDriver(-1); return configureSingleADCDriver(-1);
} else { } else {
int i = 0; for (int i = 0; i < NCHIP; ++i) {
for (i = 0; i < NCHIP; ++i) {
if (configureSingleADCDriver(i) == FAIL) { if (configureSingleADCDriver(i) == FAIL) {
return FAIL; return FAIL;
} }
@ -2075,10 +2043,8 @@ int setBurstMode(enum burstMode burst) {
uint8_t commandBytes[lenTotalBits]; uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes)); memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes int offset = padding; // bit offset for commandbytes
int ich = 0;
// loop through all bits in a value // loop through all bits in a value
int iBit = 0; for (int iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
for (iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
commandBytes[offset++] = commandBytes[offset++] =
((value >> (ASIC_GLOBAL_SETT_MAX_BITS - 1 - iBit)) & 0x1); ((value >> (ASIC_GLOBAL_SETT_MAX_BITS - 1 - iBit)) & 0x1);
} }
@ -2089,10 +2055,9 @@ int setBurstMode(enum burstMode burst) {
memset(buffer, 0, len); memset(buffer, 0, len);
offset = 0; offset = 0;
// loop through buffer elements // loop through buffer elements
for (ich = 0; ich < len; ++ich) { for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element // loop through each bit in buffer element
int iBit = 0; for (int iBit = 0; iBit < 8; ++iBit) {
for (iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit)); buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
} }
} }
@ -2235,25 +2200,20 @@ void *start_timer(void *arg) {
// Generate data // Generate data
char imageData[imagesize]; char imageData[imagesize];
memset(imageData, 0, imagesize); memset(imageData, 0, imagesize);
{ for (int i = 0; i < imagesize; i += sizeof(uint16_t)) {
int i = 0; *((uint16_t *)(imageData + i)) = i;
for (i = 0; i < imagesize; i += sizeof(uint16_t)) {
*((uint16_t *)(imageData + i)) = i;
}
} }
{ {
int repeatNr = 0;
int frameHeaderNr = 0; int frameHeaderNr = 0;
// loop over number of repeats // loop over number of repeats
for (repeatNr = 0; repeatNr != numRepeats; ++repeatNr) { for (int repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
struct timespec rbegin, rend; struct timespec rbegin, rend;
clock_gettime(CLOCK_REALTIME, &rbegin); clock_gettime(CLOCK_REALTIME, &rbegin);
int frameNr = 0;
// loop over number of frames // loop over number of frames
for (frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // update the virtual stop from stop server
virtual_stop = ComVirtual_getStop(); virtual_stop = ComVirtual_getStop();

View File

@ -5,7 +5,7 @@ support_lib = ../../slsSupportLib/include/
CROSS = nios2-buildroot-linux-gnu- CROSS = nios2-buildroot-linux-gnu-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -DMYTHEN3D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) -DDEBUG1 #-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -DMYTHEN3D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm
PROGS = mythen3DetectorServer PROGS = mythen3DetectorServer
DESTDIR ?= bin DESTDIR ?= bin

View File

@ -39,11 +39,15 @@ int virtual_status = 0;
int virtual_stop = 0; int virtual_stop = 0;
#endif #endif
sls_detector_module *detectorModules = NULL;
int *detectorChans = NULL;
int *detectorDacs = NULL;
enum TLogLevel trimmingPrint = logINFO;
int32_t clkPhase[NUM_CLOCKS] = {}; int32_t clkPhase[NUM_CLOCKS] = {};
uint32_t clkDivider[NUM_CLOCKS] = {}; uint32_t clkDivider[NUM_CLOCKS] = {};
int highvoltage = 0; int highvoltage = 0;
int dacValues[NDAC] = {};
int detPos[2] = {}; int detPos[2] = {};
uint32_t countermask = uint32_t countermask =
0; // will be removed later when in firmware converted to mask 0; // will be removed later when in firmware converted to mask
@ -204,9 +208,8 @@ int testBus() {
int ret = OK; int ret = OK;
u_int32_t addr = DTA_OFFSET_REG; u_int32_t addr = DTA_OFFSET_REG;
u_int32_t times = 1000 * 1000; u_int32_t times = 1000 * 1000;
u_int32_t i = 0;
for (i = 0; i < times; ++i) { for (u_int32_t i = 0; i < times; ++i) {
bus_w(addr, i * 100); bus_w(addr, i * 100);
if (i * 100 != bus_r(addr)) { if (i * 100 != bus_r(addr)) {
LOG(logERROR, LOG(logERROR,
@ -340,9 +343,42 @@ void initStopServer() {
/* set up detector */ /* set up detector */
void allocateDetectorStructureMemory() {
// Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHIP * NCHAN * sizeof(int));
detectorDacs = malloc(NDAC * sizeof(int));
LOG(logDEBUG1,
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
(detectorModules)->nchip = NCHIP;
(detectorModules)->nchan = NCHIP * NCHAN;
(detectorModules)->reg = UNINITIALIZED;
(detectorModules)->iodelay = 0;
(detectorModules)->tau = 0;
(detectorModules)->eV = 0;
// thisSettings = UNINITIALIZED;
// initialize dacs
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
detectorDacs[idac] = 0;
}
// if trimval requested, should return -1 to acknowledge unknown
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = -1;
}
}
void setupDetector() { void setupDetector() {
LOG(logINFO, ("This Server is for 1 Mythen3 module \n")); LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
allocateDetectorStructureMemory();
clkDivider[READOUT_C0] = DEFAULT_READOUT_C0; clkDivider[READOUT_C0] = DEFAULT_READOUT_C0;
clkDivider[READOUT_C1] = DEFAULT_READOUT_C1; clkDivider[READOUT_C1] = DEFAULT_READOUT_C1;
clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0; clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0;
@ -350,14 +386,9 @@ void setupDetector() {
clkDivider[SYSTEM_C2] = DEFAULT_SYSTEM_C2; clkDivider[SYSTEM_C2] = DEFAULT_SYSTEM_C2;
highvoltage = 0; highvoltage = 0;
{ trimmingPrint = logINFO;
int i; for (int i = 0; i < NUM_CLOCKS; ++i) {
for (i = 0; i < NUM_CLOCKS; ++i) { clkPhase[i] = 0;
clkPhase[i] = 0;
}
for (i = 0; i < NDAC; ++i) {
dacValues[i] = 0;
}
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; virtual_status = 0;
@ -404,10 +435,13 @@ int setDefaultDacs() {
int ret = OK; int ret = OK;
LOG(logINFOBLUE, ("Setting Default Dac values\n")); LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{ {
int i = 0;
const int defaultvals[NDAC] = DEFAULT_DAC_VALS; const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
for (i = 0; i < NDAC; ++i) { for (int i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i, defaultvals[i], 0); setDAC((enum DACINDEX)i, defaultvals[i], 0);
if (detectorDacs[i] != defaultvals[i]) {
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i,
defaultvals[i], detectorDacs[i]));
}
} }
} }
return ret; return ret;
@ -484,7 +518,251 @@ int setDynamicRange(int dr) {
} }
} }
/* parameters - speed, readout */ /* parameters - module, speed, readout */
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module\n"));
/* future implementation
// settings (not yet implemented)
setSettings((enum detectorSettings)myMod.reg);
if (myMod.reg >= 0) {
detectorModules->reg = myMod.reg;
}
// threshold
if (myMod.eV >= 0)
setThresholdEnergy(myMod.eV);
else {
// (loading a random trim file) (dont return fail)
setSettings(UNDEFINED);
LOG(logERROR,
("Settings has been changed to undefined (random trim
file)\n"));
}
*/
// dacs
for (int i = 0; i < NDAC; ++i) {
// ignore dacs with -1
if (myMod.dacs[i] != -1) {
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
if (myMod.dacs[i] != detectorDacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n",
i);
LOG(logERROR, (mess));
// setSettings(UNDEFINED);
// LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
}
// trimbits
if (myMod.nchan == 0) {
LOG(logINFO, ("Setting module without trimbits\n"));
} else {
// set trimbits
if (setTrimbits(myMod.chanregs) == FAIL) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess));
// setSettings(UNDEFINED);
// LOG(logERROR, ("Settings has been changed to undefined (random "
// "trim file)\n"));
return FAIL;
}
}
return OK;
}
int getModule(sls_detector_module *myMod) {
// copy local module to myMod
if (detectorModules) {
if (copyModule(myMod, detectorModules) == FAIL)
return FAIL;
} else
return FAIL;
return OK;
}
int setBit(int ibit, int patword) { return patword |= (1 << ibit); }
int clearBit(int ibit, int patword) { return patword &= ~(1 << ibit); }
int setTrimbits(int *trimbits) {
LOG(logINFOBLUE, ("Setting trimbits\n"));
// validate
for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) {
if (trimbits[ichan] < 0 || trimbits[ichan] > 63) {
LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid\n",
trimbits[ichan], ichan));
return FAIL;
}
}
LOG(logINFO, ("Trimbits validated\n"));
trimmingPrint = logDEBUG5;
uint64_t patword = 0;
int iaddr = 0;
for (int ichip = 0; ichip < NCHIP; ichip++) {
LOG(logDEBUG1, (" Chip %d\n", ichip));
iaddr = 0;
patword = 0;
writePatternWord(iaddr++, patword);
// chip select
patword = setBit(SIGNAL_TBLoad_1 + ichip, patword);
writePatternWord(iaddr++, patword);
// reset trimbits
patword = setBit(SIGNAL_resStorage, patword);
patword = setBit(SIGNAL_resCounter, patword);
writePatternWord(iaddr++, patword);
writePatternWord(iaddr++, patword);
patword = clearBit(SIGNAL_resStorage, patword);
patword = clearBit(SIGNAL_resCounter, patword);
writePatternWord(iaddr++, patword);
writePatternWord(iaddr++, patword);
// select first channel
patword = setBit(SIGNAL_CHSserialIN, patword);
writePatternWord(iaddr++, patword);
// 1 clk pulse
patword = setBit(SIGNAL_CHSclk, patword);
writePatternWord(iaddr++, patword);
patword = clearBit(SIGNAL_CHSclk, patword);
// clear 1st channel
writePatternWord(iaddr++, patword);
patword = clearBit(SIGNAL_CHSserialIN, patword);
// 2 clk pulses
for (int i = 0; i < 2; i++) {
patword = setBit(SIGNAL_CHSclk, patword);
writePatternWord(iaddr++, patword);
patword = clearBit(SIGNAL_CHSclk, patword);
writePatternWord(iaddr++, patword);
}
// for each channel (all chips)
for (int ich = 0; ich < NCHAN_1_COUNTER; ich++) {
LOG(logDEBUG1, (" Chip %d, Channel %d\n", ichip, ich));
int val = trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS +
NCOUNTERS * ich] +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS +
NCOUNTERS * ich + 1] *
64 +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS +
NCOUNTERS * ich + 2] *
64 * 64;
// push 6 0 bits
for (int i = 0; i < 6; i++) {
patword = clearBit(SIGNAL_serialIN, patword);
patword = clearBit(SIGNAL_clk, patword);
writePatternWord(iaddr++, patword);
patword = setBit(SIGNAL_clk, patword);
writePatternWord(iaddr++, patword);
}
// deserialize
for (int i = 0; i < 18; i++) {
if (val & (1 << i)) {
patword = setBit(SIGNAL_serialIN, patword);
} else {
patword = clearBit(SIGNAL_serialIN, patword);
}
patword = clearBit(SIGNAL_clk, patword);
writePatternWord(iaddr++, patword);
patword = setBit(SIGNAL_clk, patword);
writePatternWord(iaddr++, patword);
}
writePatternWord(iaddr++, patword);
writePatternWord(iaddr++, patword);
// move to next channel
for (int i = 0; i < 3; i++) {
patword = setBit(SIGNAL_CHSclk, patword);
writePatternWord(iaddr++, patword);
patword = clearBit(SIGNAL_CHSclk, patword);
writePatternWord(iaddr++, patword);
}
}
// chip unselect
patword = clearBit(SIGNAL_TBLoad_1 + ichip, patword);
writePatternWord(iaddr++, patword);
// last iaddr check
if (iaddr >= MAX_PATTERN_LENGTH) {
LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n",
iaddr, MAX_PATTERN_LENGTH));
trimmingPrint = logINFO;
return FAIL;
}
// set pattern wait address
for (int i = 0; i <= 2; i++)
setPatternWaitAddress(i, MAX_PATTERN_LENGTH - 1);
// pattern loop
for (int i = 0; i <= 2; i++) {
int stop = MAX_PATTERN_LENGTH - 1, nloop = 0;
setPatternLoop(i, &stop, &stop, &nloop);
}
// pattern limits
{
int start = 0, nloop = 0;
setPatternLoop(-1, &start, &iaddr, &nloop);
}
// load the trimbits
#ifndef VIRTUAL
startStateMachine();
#endif
}
// copy trimbits locally
for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) {
detectorChans[ichan] = trimbits[ichan];
}
trimmingPrint = logINFO;
LOG(logINFO, ("All trimbits have been loaded\n"));
return OK;
}
int setAllTrimbits(int val) {
int *trimbits = malloc(sizeof(int) * ((detectorModules)->nchan));
for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) {
trimbits[ichan] = val;
}
if (setTrimbits(trimbits) == FAIL) {
LOG(logERROR, ("Could not set all trimbits to %d\n", val));
free(trimbits);
return FAIL;
}
// setSettings(UNDEFINED);
// LOG(logERROR, ("Settings has been changed to undefined (random "
// "trim file)\n"));
LOG(logINFO, ("All trimbits have been set to %d\n", val));
free(trimbits);
return OK;
}
int getAllTrimbits() {
int value = detectorChans[0];
if (detectorModules) {
for (int ichan = 0; ichan < ((detectorModules)->nchan); ichan++) {
if (detectorChans[ichan] != value) {
value = -1;
break;
}
}
}
LOG(logINFO, ("Value of all Trimbits: %d\n", value));
return value;
}
void setNumFrames(int64_t val) { void setNumFrames(int64_t val) {
if (val > 0) { if (val > 0) {
@ -686,29 +964,29 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind],
val, (mV ? "mV" : "dac units"))); val, (mV ? "mV" : "dac units")));
if (!mV) { if (!mV) {
dacValues[ind] = val; detectorDacs[ind] = val;
} }
// convert to dac units // convert to dac units
else if (LTC2620_D_VoltageToDac(val, &dacval) == OK) { else if (LTC2620_D_VoltageToDac(val, &dacval) == OK) {
dacValues[ind] = dacval; detectorDacs[ind] = dacval;
} }
#else #else
if (LTC2620_D_SetDACValue((int)ind, val, mV, dac_names[ind], &dacval) == if (LTC2620_D_SetDACValue((int)ind, val, mV, dac_names[ind], &dacval) ==
OK) { OK) {
dacValues[ind] = dacval; detectorDacs[ind] = dacval;
} }
#endif #endif
} }
int getDAC(enum DACINDEX ind, int mV) { int getDAC(enum DACINDEX ind, int mV) {
if (!mV) { if (!mV) {
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n", ind, dacValues[ind])); LOG(logDEBUG1, ("Getting DAC %d : %d dac\n", ind, detectorDacs[ind]));
return dacValues[ind]; return detectorDacs[ind];
} }
int voltage = -1; int voltage = -1;
LTC2620_D_DacToVoltage(dacValues[ind], &voltage); LTC2620_D_DacToVoltage(detectorDacs[ind], &voltage);
LOG(logDEBUG1, LOG(logDEBUG1,
("Getting DAC %d : %d dac (%d mV)\n", ind, dacValues[ind], voltage)); ("Getting DAC %d : %d dac (%d mV)\n", ind, detectorDacs[ind], voltage));
return voltage; return voltage;
} }
@ -918,7 +1196,7 @@ uint64_t readPatternWord(int addr) {
return -1; return -1;
} }
LOG(logINFO, (" Reading Pattern Word (addr:0x%x)\n", addr)); LOG(trimmingPrint, (" Reading Pattern Word (addr:0x%x)\n", addr));
uint32_t reg_lsb = uint32_t reg_lsb =
PATTERN_STEP0_LSB_REG + PATTERN_STEP0_LSB_REG +
addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset
@ -934,6 +1212,7 @@ uint64_t readPatternWord(int addr) {
} }
uint64_t writePatternWord(int addr, uint64_t word) { uint64_t writePatternWord(int addr, uint64_t word) {
// get // get
if ((int64_t)word == -1) if ((int64_t)word == -1)
return readPatternWord(addr); return readPatternWord(addr);
@ -945,25 +1224,23 @@ uint64_t writePatternWord(int addr, uint64_t word) {
addr, MAX_PATTERN_LENGTH)); addr, MAX_PATTERN_LENGTH));
return -1; return -1;
} }
LOG(trimmingPrint, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr,
(long long int)word));
LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr, // write word
(long long int)word));
uint32_t reg_lsb = uint32_t reg_lsb =
PATTERN_STEP0_LSB_REG + PATTERN_STEP0_LSB_REG +
addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset
// of the word to write (addr) // of the word to write (addr)
uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2; uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2;
// write word
set64BitReg(word, reg_lsb, reg_msb); set64BitReg(word, reg_lsb, reg_msb);
LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n",
get64BitReg(reg_lsb, reg_msb))); get64BitReg(reg_lsb, reg_msb)));
return readPatternWord(addr); return readPatternWord(addr);
} }
int setPatternWaitAddress(int level, int addr) { int setPatternWaitAddress(int level, int addr) {
// error (handled in tcp) // error (handled in tcp)
if (addr >= MAX_PATTERN_LENGTH) { if (addr >= MAX_PATTERN_LENGTH) {
LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. " LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. "
@ -1001,8 +1278,9 @@ int setPatternWaitAddress(int level, int addr) {
// set // set
if (addr >= 0) { if (addr >= 0) {
LOG(logINFO, ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", LOG(trimmingPrint,
level, addr)); ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", level,
addr));
bus_w(reg, ((addr << offset) & mask)); bus_w(reg, ((addr << offset) & mask));
} }
@ -1039,8 +1317,8 @@ uint64_t setPatternWaitTime(int level, uint64_t t) {
// set // set
if ((int64_t)t >= 0) { if ((int64_t)t >= 0) {
LOG(logINFO, ("Setting Pattern Wait Time (level:%d, t:%lld)\n", level, LOG(trimmingPrint, ("Setting Pattern Wait Time (level:%d, t:%lld)\n",
(long long int)t)); level, (long long int)t));
set64BitReg(t, regl, regm); set64BitReg(t, regl, regm);
} }
@ -1059,6 +1337,10 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
"stopaddr:0x%x) must be " "stopaddr:0x%x) must be "
"less than 0x%x\n", "less than 0x%x\n",
*startAddr, *stopAddr, MAX_PATTERN_LENGTH)); *startAddr, *stopAddr, MAX_PATTERN_LENGTH));
*startAddr = -1;
*stopAddr = -1;
*nLoop = -1;
return;
} }
uint32_t addr = 0; uint32_t addr = 0;
@ -1116,7 +1398,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
if (level >= 0) { if (level >= 0) {
// set iteration // set iteration
if (*nLoop >= 0) { if (*nLoop >= 0) {
LOG(logINFO, LOG(trimmingPrint,
("Setting Pattern Loop (level:%d, nLoop:%d)\n", level, *nLoop)); ("Setting Pattern Loop (level:%d, nLoop:%d)\n", level, *nLoop));
bus_w(nLoopReg, *nLoop); bus_w(nLoopReg, *nLoop);
} }
@ -1126,12 +1408,11 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// set // set
if (*startAddr >= 0 && *stopAddr >= 0) { if (*startAddr >= 0 && *stopAddr >= 0) {
// writing start and stop addr // writing start and stop addr
LOG(logINFO, LOG(trimmingPrint, ("Setting Pattern Loop (level:%d, startaddr:0x%x, "
("Setting Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n", "stopaddr:0x%x)\n",
level, *startAddr, *stopAddr)); level, *startAddr, *stopAddr));
bus_w(addr, ((*startAddr << startOffset) & startMask) | bus_w(addr, ((*startAddr << startOffset) & startMask) |
((*stopAddr << stopOffset) & stopMask)); ((*stopAddr << stopOffset) & stopMask));
LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
} }
// get // get
@ -1352,13 +1633,10 @@ int setClockDivider(enum CLKINDEX ind, int val) {
// Remembering old phases in degrees // Remembering old phases in degrees
int oldPhases[NUM_CLOCKS]; int oldPhases[NUM_CLOCKS];
{ for (int i = 0; i < NUM_CLOCKS; ++i) {
int i = 0; oldPhases[i] = getPhase(i, 1);
for (i = 0; i < NUM_CLOCKS; ++i) { LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
oldPhases[i] = getPhase(i, 1); clock_names[ind], ind, oldPhases[i]));
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
clock_names[ind], ind, oldPhases[i]));
}
} }
// Calculate and set output frequency // Calculate and set output frequency
@ -1380,16 +1658,13 @@ int setClockDivider(enum CLKINDEX ind, int val) {
} }
// set the phase in degrees (reset by pll) // set the phase in degrees (reset by pll)
{ for (int i = 0; i < NUM_CLOCKS; ++i) {
int i = 0; int currPhaseDeg = getPhase(i, 1);
for (i = 0; i < NUM_CLOCKS; ++i) { if (oldPhases[i] != currPhaseDeg) {
int currPhaseDeg = getPhase(i, 1); LOG(logINFO,
if (oldPhases[i] != currPhaseDeg) { ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
LOG(logINFO, clock_names[i], i, currPhaseDeg, oldPhases[i]));
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", setPhase(i, oldPhases[i], 1);
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
} }
} }
return OK; return OK;
@ -1462,68 +1737,58 @@ void *start_timer(void *arg) {
// Generate data // Generate data
char imageData[imagesize]; char imageData[imagesize];
memset(imageData, 0, imagesize); memset(imageData, 0, imagesize);
{ for (int i = 0; i < imagesize; i += sizeof(uint8_t)) {
int i = 0; *((uint8_t *)(imageData + i)) = i;
for (i = 0; i < imagesize; i += sizeof(uint8_t)) {
*((uint8_t *)(imageData + i)) = i;
}
} }
// Send data // Send data
{ // loop over number of frames
int frameNr = 1; for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// loop over number of frames
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // update the virtual stop from stop server
virtual_stop = ComVirtual_getStop(); virtual_stop = ComVirtual_getStop();
// check if virtual_stop is high // check if virtual_stop is high
if (virtual_stop == 1) { if (virtual_stop == 1) {
break; break;
} }
// sleep for exposure time // sleep for exposure time
struct timespec begin, end; struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
usleep(expUs); usleep(expUs);
int srcOffset = 0; int srcOffset = 0;
// loop packet // loop packet
{ for (int i = 0; i != PACKETS_PER_FRAME; ++i) {
int i = 0; char packetData[packetSize];
for (i = 0; i != PACKETS_PER_FRAME; ++i) { memset(packetData, 0, packetSize);
char packetData[packetSize];
memset(packetData, 0, packetSize);
// set header // set header
sls_detector_header *header = sls_detector_header *header = (sls_detector_header *)(packetData);
(sls_detector_header *)(packetData); header->detType = (uint16_t)myDetectorType;
header->detType = (uint16_t)myDetectorType; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->frameNumber = frameNr + 1;
header->frameNumber = frameNr + 1; header->packetNumber = i;
header->packetNumber = i; header->modId = 0;
header->modId = 0; header->row = detPos[X];
header->row = detPos[X]; header->column = detPos[Y];
header->column = detPos[Y];
// fill data // fill data
memcpy(packetData + sizeof(sls_detector_header), memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize); imageData + srcOffset, dataSize);
srcOffset += dataSize; srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, packetData, packetSize);
} }
} LOG(logINFO, ("Sent frame: %d\n", frameNr));
LOG(logINFO, ("Sent frame: %d\n", frameNr)); clock_gettime(CLOCK_REALTIME, &end);
clock_gettime(CLOCK_REALTIME, &end); int64_t timeNs =
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
(end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime) // sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame if (frameNr < numFrames) { // if there is a next frame
if (periodNs > timeNs) { if (periodNs > timeNs) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
}
} }
} }
} }
@ -1655,6 +1920,56 @@ u_int32_t runBusy() {
/* common */ /* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber >= 0) {
destMod->serialnumber = srcMod->serialnumber;
}
// no trimbit feature
if (destMod->nchan && ((srcMod->nchan) > (destMod->nchan))) {
LOG(logINFO, ("Number of channels of source is larger than number of "
"channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac) > (destMod->ndac)) {
LOG(logINFO, ("Number of dacs of source is larger than number of dacs "
"of destination\n"));
return FAIL;
}
LOG(logDEBUG1, ("DACs: src %d, dest %d\n", srcMod->ndac, destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n", srcMod->nchan, destMod->nchan));
destMod->ndac = srcMod->ndac;
destMod->nchip = srcMod->nchip;
destMod->nchan = srcMod->nchan;
if (srcMod->reg >= 0)
destMod->reg = srcMod->reg;
/*
if (srcMod->iodelay >= 0)
destMod->iodelay = srcMod->iodelay;
if (srcMod->tau >= 0)
destMod->tau = srcMod->tau;
if (srcMod->eV >= 0)
destMod->eV = srcMod->eV;
*/
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
if (destMod->nchan != 0) {
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
}
} else
LOG(logINFO, ("Not Copying trimbits\n"));
for (int idac = 0; idac < (srcMod->ndac); idac++) {
if (*((srcMod->dacs) + idac) >= 0) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return OK;
}
int calculateDataBytes() { int calculateDataBytes() {
int numCounters = __builtin_popcount(getCounterMask()); int numCounters = __builtin_popcount(getCounterMask());
int dr = setDynamicRange(-1); int dr = setDynamicRange(-1);

View File

@ -45,7 +45,8 @@
#define MAX_PATTERN_LENGTH (0x2000) // maximum number of words (64bit) #define MAX_PATTERN_LENGTH (0x2000) // maximum number of words (64bit)
/** Other Definitions */ /** Other Definitions */
#define BIT16_MASK (0xFFFF) #define BIT16_MASK (0xFFFF)
#define MAX_TRIMBITS_VALUE (63)
/* Enums */ /* Enums */
enum DACINDEX { enum DACINDEX {
@ -126,3 +127,31 @@ typedef struct udp_header_struct {
} udp_header; } udp_header;
#define UDP_IP_HEADER_LENGTH_BYTES (28) #define UDP_IP_HEADER_LENGTH_BYTES (28)
#define PACKETS_PER_FRAME (2) #define PACKETS_PER_FRAME (2)
/** Signal Definitions */
#define SIGNAL_TBLoad_1 (0)
#define SIGNAL_TBLoad_2 (1)
#define SIGNAL_TBLoad_3 (2)
#define SIGNAL_TBLoad_4 (3)
#define SIGNAL_TBLoad_5 (4)
#define SIGNAL_TBLoad_6 (5)
#define SIGNAL_TBLoad_7 (6)
#define SIGNAL_TBLoad_8 (7)
#define SIGNAL_TBLoad_9 (8)
#define SIGNAL_TBLoad_10 (9)
#define SIGNAL_AnaMode (10)
#define SIGNAL_CHSserialIN (11)
#define SIGNAL_READOUT (12)
#define SIGNAL_pulse (13)
#define SIGNAL_EN1 (14)
#define SIGNAL_EN2 (15)
#define SIGNAL_EN3 (16)
#define SIGNAL_clk (17)
#define SIGNAL_SRmode (18)
#define SIGNAL_serialIN (19)
#define SIGNAL_STO (20)
#define SIGNAL_STATLOAD (21)
#define SIGNAL_resStorage (22)
#define SIGNAL_resCounter (23)
#define SIGNAL_CHSclk (24)
#define SIGNAL_exposing (25)

View File

@ -99,7 +99,7 @@ void getModuleConfiguration();
#endif #endif
// set up detector // set up detector
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
void allocateDetectorStructureMemory(); void allocateDetectorStructureMemory();
#endif #endif
void setupDetector(); void setupDetector();
@ -252,11 +252,17 @@ int64_t getMeasurementTime();
#endif #endif
// parameters - module, settings // parameters - module, settings
#if (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) && \ #if (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) && (!defined(GOTTHARD2D))
(!defined(MYTHEN3D)) && (!defined(GOTTHARD2D))
int setModule(sls_detector_module myMod, char *mess); int setModule(sls_detector_module myMod, char *mess);
int getModule(sls_detector_module *myMod); int getModule(sls_detector_module *myMod);
#endif #endif
#ifdef MYTHEN3D
int setTrimbits(int *trimbits);
int setBit(int ibit, int patword);
int clearBit(int ibit, int patword);
int setAllTrimbits(int val);
int getAllTrimbits();
#endif
#if (!defined(CHIPTESTBOARDD)) && (!defined(MYTHEN3D)) #if (!defined(CHIPTESTBOARDD)) && (!defined(MYTHEN3D))
enum detectorSettings setSettings(enum detectorSettings sett); enum detectorSettings setSettings(enum detectorSettings sett);
#endif #endif
@ -534,7 +540,7 @@ u_int32_t runState(enum TLogLevel lev);
#endif #endif
// common // common
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod); int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
#endif #endif
int calculateDataBytes(); int calculateDataBytes();

View File

@ -456,7 +456,7 @@ int sendModule(int file_des, sls_detector_module *myMod) {
} }
ts += n; ts += n;
// channels // channels
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
n = sendData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan), n = sendData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan),
INT32); INT32);
if (!n) { if (!n) {
@ -473,7 +473,7 @@ int receiveModule(int file_des, sls_detector_module *myMod) {
LOG(level, ("Receiving Module\n")); LOG(level, ("Receiving Module\n"));
int ts = 0, n = 0; int ts = 0, n = 0;
int nDacs = myMod->ndac; int nDacs = myMod->ndac;
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
int nChans = myMod->nchan; // can be zero for no trimbits int nChans = myMod->nchan; // can be zero for no trimbits
LOG(level, ("nChans: %d\n", nChans)); LOG(level, ("nChans: %d\n", nChans));
#endif #endif
@ -542,7 +542,7 @@ int receiveModule(int file_des, sls_detector_module *myMod) {
ts += n; ts += n;
LOG(level, ("dacs received. %d bytes.\n", n)); LOG(level, ("dacs received. %d bytes.\n", n));
// channels // channels
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
if (((myMod->nchan) != 0) && // no trimbits if (((myMod->nchan) != 0) && // no trimbits
(nChans != (myMod->nchan))) { // with trimbits (nChans != (myMod->nchan))) { // with trimbits
LOG(logERROR, ("received wrong number of channels. " LOG(logERROR, ("received wrong number of channels. "

View File

@ -1721,10 +1721,8 @@ int read_register(int file_des) {
int set_module(int file_des) { int set_module(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
enum detectorSettings retval = -1;
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(MYTHEN3D) || \ #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(GOTTHARD2D)
defined(GOTTHARD2D)
functionNotImplemented(); functionNotImplemented();
#else #else
@ -1736,7 +1734,7 @@ int set_module(int file_des) {
// allocate to receive arguments // allocate to receive arguments
// allocate dacs // allocate dacs
myDac = (int *)malloc(getNumberOfDACs() * sizeof(int)); myDac = malloc(getNumberOfDACs() * sizeof(int));
// error // error
if (getNumberOfDACs() > 0 && myDac == NULL) { if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL; ret = FAIL;
@ -1745,10 +1743,10 @@ int set_module(int file_des) {
} else } else
module.dacs = myDac; module.dacs = myDac;
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
// allocate chans // allocate chans
if (ret == OK) { if (ret == OK) {
myChan = (int *)malloc(getTotalNumberOfChannels() * sizeof(int)); myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) { if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Could not allocate chans\n"); sprintf(mess, "Could not allocate chans\n");
@ -1764,10 +1762,8 @@ int set_module(int file_des) {
module.ndac = getNumberOfDACs(); module.ndac = getNumberOfDACs();
int ts = receiveModule(file_des, &module); int ts = receiveModule(file_des, &module);
if (ts < 0) { if (ts < 0) {
if (myChan != NULL) free(myChan);
free(myChan); free(myDac);
if (myDac != NULL)
free(myDac);
return printSocketReadError(); return printSocketReadError();
} }
LOG(logDEBUG1, ("module register is %d, nchan %d, nchip %d, " LOG(logDEBUG1, ("module register is %d, nchan %d, nchip %d, "
@ -1815,6 +1811,8 @@ int set_module(int file_des) {
case LOWGAIN: case LOWGAIN:
case MEDIUMGAIN: case MEDIUMGAIN:
case VERYHIGHGAIN: case VERYHIGHGAIN:
#elif MYTHEN3D
case GET_SETTINGS:
#endif #endif
break; break;
default: default:
@ -1823,17 +1821,17 @@ int set_module(int file_des) {
} }
ret = setModule(module, mess); ret = setModule(module, mess);
retval = getSettings(); #ifndef MYTHEN3D
enum detectorSettings retval = getSettings();
validate(module.reg, (int)retval, "set module (settings)", DEC); validate(module.reg, (int)retval, "set module (settings)", DEC);
LOG(logDEBUG1, ("Settings: %d\n", retval)); LOG(logDEBUG1, ("Settings: %d\n", retval));
#endif
} }
if (myChan != NULL) free(myChan);
free(myChan); free(myDac);
if (myDac != NULL)
free(myDac);
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, NULL, 0);
} }
int get_module(int file_des) { int get_module(int file_des) {
@ -1847,7 +1845,7 @@ int get_module(int file_des) {
// allocate to send arguments // allocate to send arguments
// allocate dacs // allocate dacs
myDac = (int *)malloc(getNumberOfDACs() * sizeof(int)); myDac = malloc(getNumberOfDACs() * sizeof(int));
// error // error
if (getNumberOfDACs() > 0 && myDac == NULL) { if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL; ret = FAIL;
@ -1856,15 +1854,14 @@ int get_module(int file_des) {
} else } else
module.dacs = myDac; module.dacs = myDac;
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(MYTHEN3D) || \ #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(GOTTHARD2D)
defined(GOTTHARD2D)
functionNotImplemented(); functionNotImplemented();
#endif #endif
#ifdef EIGERD #if defined(EIGERD) || defined(MYTHEN3D)
// allocate chans // allocate chans
if (ret == OK) { if (ret == OK) {
myChan = (int *)malloc(getTotalNumberOfChannels() * sizeof(int)); myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) { if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Could not allocate chans\n"); sprintf(mess, "Could not allocate chans\n");
@ -1882,8 +1879,7 @@ int get_module(int file_des) {
// only get // only get
LOG(logDEBUG1, ("Getting module\n")); LOG(logDEBUG1, ("Getting module\n"));
#if !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && !defined(MYTHEN3D) && \ #if !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && !defined(GOTTHARD2D)
!defined(GOTTHARD2D)
getModule(&module); getModule(&module);
#endif #endif
LOG(logDEBUG1, ("Getting module. Settings:%d\n", module.reg)); LOG(logDEBUG1, ("Getting module. Settings:%d\n", module.reg));
@ -1895,10 +1891,8 @@ int get_module(int file_des) {
if (ret != FAIL) { if (ret != FAIL) {
ret = sendModule(file_des, &module); ret = sendModule(file_des, &module);
} }
if (myChan != NULL) free(myChan);
free(myChan); free(myDac);
if (myDac != NULL)
free(myDac);
return ret; return ret;
} }
@ -3141,7 +3135,7 @@ int set_all_trimbits(int file_des) {
return printSocketReadError(); return printSocketReadError();
LOG(logDEBUG1, ("Set all trmbits to %d\n", arg)); LOG(logDEBUG1, ("Set all trmbits to %d\n", arg));
#ifndef EIGERD #if !defined(EIGERD) && !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
#else #else
@ -3154,10 +3148,12 @@ int set_all_trimbits(int file_des) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
ret = setAllTrimbits(arg); ret = setAllTrimbits(arg);
#ifdef EIGERD
// changes settings to undefined // changes settings to undefined
setSettings(UNDEFINED); setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (change all " LOG(logERROR, ("Settings has been changed to undefined (change all "
"trimbits)\n")); "trimbits)\n"));
#endif
} }
} }
// get // get
@ -3924,7 +3920,7 @@ int program_fpga(int file_des) {
// receive program // receive program
if (ret == OK) { if (ret == OK) {
char *fpgasrc = (char *)malloc(filesize); char *fpgasrc = malloc(filesize);
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0) if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0)
return printSocketReadError(); return printSocketReadError();
@ -3932,8 +3928,7 @@ int program_fpga(int file_des) {
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
// free resources // free resources
if (fpgasrc != NULL) free(fpgasrc);
free(fpgasrc);
} }
#else // jungfrau, ctb, moench #else // jungfrau, ctb, moench
@ -3961,7 +3956,7 @@ int program_fpga(int file_des) {
// erasing flash // erasing flash
if (ret != FAIL) { if (ret != FAIL) {
eraseFlash(); eraseFlash();
fpgasrc = (char *)malloc(MAX_FPGAPROGRAMSIZE); fpgasrc = malloc(MAX_FPGAPROGRAMSIZE);
} }
// writing to flash part by part // writing to flash part by part
@ -4007,8 +4002,7 @@ int program_fpga(int file_des) {
stopWritingFPGAprogram(fp); stopWritingFPGAprogram(fp);
// free resources // free resources
if (fpgasrc != NULL) free(fpgasrc);
free(fpgasrc);
if (fp != NULL) if (fp != NULL)
fclose(fp); fclose(fp);

View File

@ -108,6 +108,15 @@ class Detector {
*/ */
void setSettings(defs::detectorSettings value, Positions pos = {}); void setSettings(defs::detectorSettings value, Positions pos = {});
/** [Eiger][Mythen3] */
void loadTrimbits(const std::string &fname, Positions pos = {});
/** [Eiger][Mythen3] -1 if they are all different */
Result<int> getAllTrimbits(Positions pos = {}) const;
/**[Eiger][Mythen3] */
void setAllTrimbits(int value, Positions pos = {});
/************************************************** /**************************************************
* * * *
* Callbacks * * Callbacks *
@ -715,9 +724,6 @@ class Detector {
/** [Eiger] */ /** [Eiger] */
void setSettingsPath(const std::string &value, Positions pos = {}); void setSettingsPath(const std::string &value, Positions pos = {});
/** [Eiger] */
void loadTrimbits(const std::string &fname, Positions pos = {});
/** [Eiger] */ /** [Eiger] */
Result<bool> getParallelMode(Positions pos = {}) const; Result<bool> getParallelMode(Positions pos = {}) const;
@ -742,12 +748,6 @@ class Detector {
/** [Eiger] for client call back (gui) purposes */ /** [Eiger] for client call back (gui) purposes */
void setBottom(bool value, Positions pos = {}); void setBottom(bool value, Positions pos = {});
/** [Eiger] -1 if they are all different */
Result<int> getAllTrimbits(Positions pos = {}) const;
/**[Eiger] */
void setAllTrimbits(int value, Positions pos = {});
/**[Eiger] Returns energies in eV where the module is trimmed */ /**[Eiger] Returns energies in eV where the module is trimmed */
Result<std::vector<int>> getTrimEnergies(Positions pos = {}) const; Result<std::vector<int>> getTrimEnergies(Positions pos = {}) const;

View File

@ -563,6 +563,8 @@ class CmdProxy {
{"type", &CmdProxy::type}, {"type", &CmdProxy::type},
{"detsize", &CmdProxy::DetectorSize}, {"detsize", &CmdProxy::DetectorSize},
{"settings", &CmdProxy::settings}, {"settings", &CmdProxy::settings},
{"trimbits", &CmdProxy::trimbits},
{"trimval", &CmdProxy::trimval},
/* acquisition parameters */ /* acquisition parameters */
{"acquire", &CmdProxy::acquire}, {"acquire", &CmdProxy::acquire},
@ -751,13 +753,11 @@ class CmdProxy {
{"threshold", &CmdProxy::Threshold}, {"threshold", &CmdProxy::Threshold},
{"thresholdnotb", &CmdProxy::ThresholdNoTb}, {"thresholdnotb", &CmdProxy::ThresholdNoTb},
{"settingspath", &CmdProxy::settingspath}, {"settingspath", &CmdProxy::settingspath},
{"trimbits", &CmdProxy::trimbits},
{"gappixels", &CmdProxy::GapPixels}, {"gappixels", &CmdProxy::GapPixels},
{"parallel", &CmdProxy::parallel}, {"parallel", &CmdProxy::parallel},
{"overflow", &CmdProxy::overflow}, {"overflow", &CmdProxy::overflow},
{"storeinram", &CmdProxy::storeinram}, {"storeinram", &CmdProxy::storeinram},
{"flippeddatax", &CmdProxy::flippeddatax}, {"flippeddatax", &CmdProxy::flippeddatax},
{"trimval", &CmdProxy::trimval},
{"trimen", &CmdProxy::TrimEnergies}, {"trimen", &CmdProxy::TrimEnergies},
{"ratecorr", &CmdProxy::RateCorrection}, {"ratecorr", &CmdProxy::RateCorrection},
{"readnlines", &CmdProxy::readnlines}, {"readnlines", &CmdProxy::readnlines},
@ -1032,6 +1032,15 @@ class CmdProxy {
"g2_lc_hg | g2_lc_lg | g4_hg | g4_lg]" "g2_lc_hg | g2_lc_lg | g4_hg | g4_lg]"
"\n\t[Eiger] Use threshold or thresholdnotb."); "\n\t[Eiger] Use threshold or thresholdnotb.");
EXECUTE_SET_COMMAND_NOID_1ARG(
trimbits, loadTrimbits,
"[fname]\n\t[Eiger][Mythen3] Loads the trimbit file to detector. If no "
"extension specified, serial number of each module is attached.");
INTEGER_COMMAND(trimval, getAllTrimbits, setAllTrimbits, StringTo<int>,
"[n_trimval]\n\t[Eiger][Mythen3] All trimbits set to this "
"value. Returns -1 if all trimbits are different values.");
/* acquisition parameters */ /* acquisition parameters */
INTEGER_COMMAND_NOID( INTEGER_COMMAND_NOID(
@ -1740,11 +1749,6 @@ class CmdProxy {
settingspath, getSettingsPath, setSettingsPath, settingspath, getSettingsPath, setSettingsPath,
"[path]\n\t[Eiger] Directory where settings files are loaded from/to."); "[path]\n\t[Eiger] Directory where settings files are loaded from/to.");
EXECUTE_SET_COMMAND_NOID_1ARG(
trimbits, loadTrimbits,
"[fname]\n\t[Eiger] Loads the trimbit file to detector. If no "
"extension specified, serial number of each module is attached.");
INTEGER_COMMAND(parallel, getParallelMode, setParallelMode, StringTo<int>, INTEGER_COMMAND(parallel, getParallelMode, setParallelMode, StringTo<int>,
"[0, 1]\n\t[Eiger] Enable or disable parallel mode."); "[0, 1]\n\t[Eiger] Enable or disable parallel mode.");
@ -1762,10 +1766,6 @@ class CmdProxy {
"is top. Used to let Receivers and Gui know to flip the bottom image " "is top. Used to let Receivers and Gui know to flip the bottom image "
"over the x axis. Files are not written without the flip however."); "over the x axis. Files are not written without the flip however.");
INTEGER_COMMAND(trimval, getAllTrimbits, setAllTrimbits, StringTo<int>,
"[n_trimval]\n\t[Eiger] All trimbits set to this value. A "
"get returns -1 if all trimbits are different values.");
INTEGER_COMMAND( INTEGER_COMMAND(
readnlines, getPartialReadout, setPartialReadout, StringTo<int>, readnlines, getPartialReadout, setPartialReadout, StringTo<int>,
"[1 - 256]\n\t[Eiger] Number of rows to readout per half module " "[1 - 256]\n\t[Eiger] Number of rows to readout per half module "

View File

@ -149,6 +149,18 @@ void Detector::setSettings(const defs::detectorSettings value, Positions pos) {
pimpl->Parallel(&Module::setSettings, pos, value); pimpl->Parallel(&Module::setSettings, pos, value);
} }
void Detector::loadTrimbits(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::loadSettingsFile, pos, fname);
}
Result<int> Detector::getAllTrimbits(Positions pos) const {
return pimpl->Parallel(&Module::getAllTrimbits, pos);
}
void Detector::setAllTrimbits(int value, Positions pos) {
pimpl->Parallel(&Module::setAllTrimbits, pos, value);
}
// Callback // Callback
void Detector::registerAcquisitionFinishedCallback(void (*func)(double, int, void Detector::registerAcquisitionFinishedCallback(void (*func)(double, int,
@ -942,10 +954,6 @@ void Detector::setSettingsPath(const std::string &value, Positions pos) {
pimpl->Parallel(&Module::setSettingsDir, pos, value); pimpl->Parallel(&Module::setSettingsDir, pos, value);
} }
void Detector::loadTrimbits(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::loadSettingsFile, pos, fname);
}
Result<bool> Detector::getParallelMode(Positions pos) const { Result<bool> Detector::getParallelMode(Positions pos) const {
return pimpl->Parallel(&Module::getParallelMode, pos); return pimpl->Parallel(&Module::getParallelMode, pos);
} }
@ -978,14 +986,6 @@ void Detector::setBottom(bool value, Positions pos) {
pimpl->Parallel(&Module::setFlippedDataX, pos, value); pimpl->Parallel(&Module::setFlippedDataX, pos, value);
} }
Result<int> Detector::getAllTrimbits(Positions pos) const {
return pimpl->Parallel(&Module::setAllTrimbits, pos, -1);
}
void Detector::setAllTrimbits(int value, Positions pos) {
pimpl->Parallel(&Module::setAllTrimbits, pos, value);
}
Result<std::vector<int>> Detector::getTrimEnergies(Positions pos) const { Result<std::vector<int>> Detector::getTrimEnergies(Positions pos) const {
return pimpl->Parallel(&Module::getTrimEn, pos); return pimpl->Parallel(&Module::getTrimEn, pos);
} }

View File

@ -110,19 +110,20 @@ int64_t Module::getFirmwareVersion() {
int64_t Module::getDetectorServerVersion() { int64_t Module::getDetectorServerVersion() {
int64_t retval = -1; int64_t retval = -1;
sendToDetector(F_GET_SERVER_VERSION, nullptr, retval); sendToDetector(F_GET_SERVER_VERSION, nullptr, retval);
LOG(logDEBUG1) << "firmware version: 0x" << std::hex << retval << std::dec; LOG(logDEBUG1) << "detector server version: 0x" << std::hex << retval
<< std::dec;
return retval; return retval;
} }
int64_t Module::getSerialNumber() { int64_t Module::getSerialNumber() {
int64_t retval = -1; int64_t retval = -1;
sendToDetector(F_GET_SERIAL_NUMBER, nullptr, retval); sendToDetector(F_GET_SERIAL_NUMBER, nullptr, retval);
LOG(logDEBUG1) << "firmware version: 0x" << std::hex << retval << std::dec; LOG(logDEBUG1) << "serial number: 0x" << std::hex << retval << std::dec;
return retval; return retval;
} }
int64_t Module::getReceiverSoftwareVersion() const { int64_t Module::getReceiverSoftwareVersion() const {
LOG(logDEBUG1) << "Getting receiver software version"; LOG(logDEBUG1) << "Getting receiver version";
int64_t retval = -1; int64_t retval = -1;
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
sendToReceiver(F_GET_RECEIVER_VERSION, nullptr, retval); sendToReceiver(F_GET_RECEIVER_VERSION, nullptr, retval);
@ -450,7 +451,7 @@ int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) {
ts += n; ts += n;
LOG(level) << "dacs sent. " << n << " bytes"; LOG(level) << "dacs sent. " << n << " bytes";
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan)); n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += n; ts += n;
LOG(level) << "channels sent. " << n << " bytes"; LOG(level) << "channels sent. " << n << " bytes";
@ -472,7 +473,7 @@ int Module::receiveModule(sls_detector_module *myMod,
ts += client.Receive(myMod->dacs, sizeof(int) * (myMod->ndac)); ts += client.Receive(myMod->dacs, sizeof(int) * (myMod->ndac));
LOG(logDEBUG1) << "received dacs of size " << ts; LOG(logDEBUG1) << "received dacs of size " << ts;
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
ts += client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan)); ts += client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan));
LOG(logDEBUG1) << " nchan= " << myMod->nchan LOG(logDEBUG1) << " nchan= " << myMod->nchan
<< " nchip= " << myMod->nchip << " nchip= " << myMod->nchip
@ -907,7 +908,7 @@ void Module::loadSettingsFile(const std::string &fname) {
ostfn << fname; ostfn << fname;
// find specific file if it has detid in file name (.snxxx) // find specific file if it has detid in file name (.snxxx)
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
if (fname.find(".sn") == std::string::npos && if (fname.find(".sn") == std::string::npos &&
fname.find(".trim") == std::string::npos && fname.find(".trim") == std::string::npos &&
fname.find(".settings") == std::string::npos) { fname.find(".settings") == std::string::npos) {
@ -2509,14 +2510,20 @@ void Module::setFlippedDataX(bool value) {
sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval); sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval);
} }
int Module::setAllTrimbits(int val) { int Module::getAllTrimbits() {
int retval = -1; int retval = -1;
LOG(logDEBUG1) << "Setting all trimbits to " << val; int val = -1;
sendToDetector(F_SET_ALL_TRIMBITS, val, retval); sendToDetector(F_SET_ALL_TRIMBITS, val, retval);
LOG(logDEBUG1) << "All trimbit value: " << retval; LOG(logDEBUG1) << "All trimbit value: " << retval;
return retval; return retval;
} }
void Module::setAllTrimbits(int val) {
int retval = -1;
LOG(logDEBUG1) << "Setting all trimbits to " << val;
sendToDetector(F_SET_ALL_TRIMBITS, val, retval);
}
int Module::setTrimEn(const std::vector<int> &energies) { int Module::setTrimEn(const std::vector<int> &energies) {
if (shm()->myDetectorType != EIGER) { if (shm()->myDetectorType != EIGER) {
throw RuntimeError("setTrimEn not implemented for this detector."); throw RuntimeError("setTrimEn not implemented for this detector.");
@ -2766,7 +2773,6 @@ int Module::setAutoComparatorDisableMode(int ival) {
void Module::setModule(sls_detector_module &module, int tb) { void Module::setModule(sls_detector_module &module, int tb) {
int fnum = F_SET_MODULE; int fnum = F_SET_MODULE;
int ret = FAIL; int ret = FAIL;
int retval = -1;
LOG(logDEBUG1) << "Setting module with tb:" << tb; LOG(logDEBUG1) << "Setting module with tb:" << tb;
// to exclude trimbits // to exclude trimbits
if (tb == 0) { if (tb == 0) {
@ -2783,8 +2789,6 @@ void Module::setModule(sls_detector_module &module, int tb) {
throw RuntimeError("Detector " + std::to_string(detId) + throw RuntimeError("Detector " + std::to_string(detId) +
" returned error: " + mess); " returned error: " + mess);
} }
client.Receive(&retval, sizeof(retval));
LOG(logDEBUG1) << "Set Module returned: " << retval;
} }
sls_detector_module Module::getModule() { sls_detector_module Module::getModule() {
@ -3554,7 +3558,7 @@ sls_detector_module Module::readSettingsFile(const std::string &fname, int tb) {
auto names = getSettingsFileDacNames(); auto names = getSettingsFileDacNames();
// open file // open file
std::ifstream infile; std::ifstream infile;
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
infile.open(fname.c_str(), std::ifstream::binary); infile.open(fname.c_str(), std::ifstream::binary);
} else { } else {
infile.open(fname.c_str(), std::ios_base::in); infile.open(fname.c_str(), std::ios_base::in);
@ -3565,30 +3569,16 @@ sls_detector_module Module::readSettingsFile(const std::string &fname, int tb) {
// eiger // eiger
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER) {
bool allread = false;
infile.read(reinterpret_cast<char *>(myMod.dacs), infile.read(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac)); sizeof(int) * (myMod.ndac));
if (infile.good()) { infile.read(reinterpret_cast<char *>(&myMod.iodelay),
infile.read(reinterpret_cast<char *>(&myMod.iodelay), sizeof(myMod.iodelay));
sizeof(myMod.iodelay)); infile.read(reinterpret_cast<char *>(&myMod.tau), sizeof(myMod.tau));
if (infile.good()) { if (tb != 0) {
infile.read(reinterpret_cast<char *>(&myMod.tau), infile.read(reinterpret_cast<char *>(myMod.chanregs),
sizeof(myMod.tau)); sizeof(int) * (myMod.nchan));
if (tb != 0) {
if (infile.good()) {
infile.read(reinterpret_cast<char *>(myMod.chanregs),
sizeof(int) * (myMod.nchan));
if (infile) {
allread = true;
}
}
} else if (infile) {
allread = true;
}
}
} }
if (!allread) { if (!infile) {
infile.close();
throw RuntimeError("readSettingsFile: Could not load all values " throw RuntimeError("readSettingsFile: Could not load all values "
"for settings for " + "for settings for " +
fname); fname);
@ -3600,6 +3590,23 @@ sls_detector_module Module::readSettingsFile(const std::string &fname, int tb) {
LOG(logDEBUG1) << "tau:" << myMod.tau; LOG(logDEBUG1) << "tau:" << myMod.tau;
} }
// mythen3 (dacs, trimbits)
else if (shm()->myDetectorType == MYTHEN3) {
infile.read(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac));
infile.read(reinterpret_cast<char *>(myMod.chanregs),
sizeof(int) * (myMod.nchan));
if (!infile) {
throw RuntimeError("readSettingsFile: Could not load all values "
"for settings for " +
fname);
}
for (int i = 0; i < myMod.ndac; ++i) {
LOG(logDEBUG1) << "dac " << i << ":" << myMod.dacs[i];
}
}
// gotthard, jungfrau // gotthard, jungfrau
else { else {
size_t idac = 0; size_t idac = 0;
@ -3626,18 +3633,15 @@ sls_detector_module Module::readSettingsFile(const std::string &fname, int tb) {
if (!found) { if (!found) {
throw RuntimeError("readSettingsFile: Unknown dac: " + throw RuntimeError("readSettingsFile: Unknown dac: " +
sargname); sargname);
infile.close();
} }
} }
// not all read // not all read
if (idac != names.size()) { if (idac != names.size()) {
infile.close();
throw RuntimeError("Could read only " + std::to_string(idac) + throw RuntimeError("Could read only " + std::to_string(idac) +
" dacs. Expected " + " dacs. Expected " +
std::to_string(names.size()) + " dacs"); std::to_string(names.size()) + " dacs");
} }
} }
infile.close();
LOG(logINFO) << "Settings file loaded: " << fname.c_str(); LOG(logINFO) << "Settings file loaded: " << fname.c_str();
return myMod; return myMod;
} }
@ -3678,7 +3682,6 @@ void Module::writeSettingsFile(const std::string &fname,
outfile << names[i] << " " << mod.dacs[i] << std::endl; outfile << names[i] << " " << mod.dacs[i] << std::endl;
} }
} }
outfile.close();
} }
std::vector<std::string> Module::getSettingsFileDacNames() { std::vector<std::string> Module::getSettingsFileDacNames() {
@ -3694,6 +3697,8 @@ std::vector<std::string> Module::getSettingsFileDacNames() {
"VDAC6", "VDAC7", "VDAC8", "VDAC9", "VDAC10", "VDAC11", "VDAC6", "VDAC7", "VDAC8", "VDAC9", "VDAC10", "VDAC11",
"VDAC12", "VDAC13", "VDAC14", "VDAC15"}; "VDAC12", "VDAC13", "VDAC14", "VDAC15"};
break; break;
case MYTHEN3:
break;
default: default:
throw RuntimeError( throw RuntimeError(
"Unknown detector type - unknown format for settings file"); "Unknown detector type - unknown format for settings file");

View File

@ -318,11 +318,6 @@ class Module : public virtual slsDetectorDefs {
*/ */
std::string setSettingsDir(const std::string &dir); std::string setSettingsDir(const std::string &dir);
/**
* Loads the modules settings/trimbits reading from a specific file
* file name extension is automatically generated.
* @param fname specific settings/trimbits file
*/
void loadSettingsFile(const std::string &fname); void loadSettingsFile(const std::string &fname);
/** /**
@ -1127,12 +1122,8 @@ class Module : public virtual slsDetectorDefs {
*/ */
void setFlippedDataX(bool value); void setFlippedDataX(bool value);
/** int getAllTrimbits();
* Sets all the trimbits to a particular value (Eiger) void setAllTrimbits(int val);
* @param val trimbit value
* @returns OK or FAIL
*/
int setAllTrimbits(int val);
/** /**
* Sets the number of trim energies and their value (Eiger) * Sets the number of trim energies and their value (Eiger)

View File

@ -593,8 +593,8 @@ typedef struct {
#ifdef __cplusplus #ifdef __cplusplus
sls_detector_module() sls_detector_module()
: serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0), : serialnumber(0), nchan(0), nchip(0), ndac(0), reg(-1), iodelay(0),
tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {} tau(0), eV(-1), dacs(nullptr), chanregs(nullptr) {}
explicit sls_detector_module(slsDetectorDefs::detectorType type) explicit sls_detector_module(slsDetectorDefs::detectorType type)
: sls_detector_module() { : sls_detector_module() {

View File

@ -3,11 +3,11 @@
#define APILIB 0x200409 #define APILIB 0x200409
#define APIRECEIVER 0x200409 #define APIRECEIVER 0x200409
#define APIGUI 0x200409 #define APIGUI 0x200409
#define APIEIGER 0x200409
#define APICTB 0x200409
#define APIGOTTHARD 0x200409
#define APIJUNGFRAU 0x200409
#define APIMYTHEN3 0x200428
#define APIGOTTHARD2 0x200429
#define APIMOENCH 0x200429 #define APICTB 0x200508
#define APIGOTTHARD 0x200508
#define APIGOTTHARD2 0x200508
#define APIJUNGFRAU 0x200508
#define APIMOENCH 0x200508
#define APIEIGER 0x200508
#define APIMYTHEN3 0x200508