mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
gotthard2: veto reference
This commit is contained in:
Binary file not shown.
@ -43,6 +43,7 @@ int defaultDacValues[NDAC] = {0};
|
||||
int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {0};
|
||||
int injectedChannelsOffset = 0;
|
||||
int injectedChannelsIncrement = 0;
|
||||
int vetoReference[NCHIP][NCHAN];
|
||||
int detPos[2] = {0, 0};
|
||||
|
||||
int isInitCheckDone() {
|
||||
@ -334,9 +335,13 @@ void setupDetector() {
|
||||
clkFrequency[SYSTEM_C1] = DEFAULT_SYSTEM_C1;
|
||||
clkFrequency[SYSTEM_C2] = DEFAULT_SYSTEM_C2;
|
||||
clkFrequency[SYSTEM_C3] = DEFAULT_SYSTEM_C3;
|
||||
|
||||
detPos[0] = 0;
|
||||
detPos[1] = 0;
|
||||
|
||||
highvoltage = 0;
|
||||
injectedChannelsOffset = 0;
|
||||
injectedChannelsIncrement = 0;
|
||||
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
||||
@ -344,11 +349,19 @@ void setupDetector() {
|
||||
}
|
||||
for (i = 0; i < NDAC; ++i) {
|
||||
dacValues[i] = 0;
|
||||
defaultDacValues[i] = 0;
|
||||
}
|
||||
for (i = 0; i < ONCHIP_NDAC; ++i) {
|
||||
for (j = 0; j < NCHIP; ++j)
|
||||
onChipdacValues[i][j] = -1;
|
||||
}
|
||||
for (j = 0; j < NCHIP; ++j) {
|
||||
onChipdacValues[i][j] = -1;
|
||||
defaultOnChipdacValues[i][j] = -1;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < NCHIP; ++i) {
|
||||
for (j = 0; j < NCHAN; ++j) {
|
||||
vetoReference[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1097,6 +1110,111 @@ void getInjectedChannels(int* offset, int* increment) {
|
||||
*increment = injectedChannelsIncrement;
|
||||
}
|
||||
|
||||
int setVetoPhoton(int chipIndex, int gainIndex, int* values) {
|
||||
FILE_LOG(logINFO, ("Setting veto photon [chip:%d, G%d]\n", chipIndex, gainIndex));
|
||||
|
||||
// add gain bits
|
||||
{
|
||||
int gainValue = 0;
|
||||
switch (gainIndex) {
|
||||
case 0:
|
||||
gainValue = ASIC_G0_VAL;
|
||||
break;
|
||||
case 1:
|
||||
gainValue = ASIC_G1_VAL;
|
||||
break;
|
||||
case 2:
|
||||
gainValue = ASIC_G2_VAL;
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR, ("Unknown gain index %d\n", gainIndex));
|
||||
return FAIL;
|
||||
}
|
||||
FILE_LOG(logDEBUG1, ("Adding gain bits\n"));
|
||||
int i = 0;
|
||||
for (i = 0; i < NCHAN; ++i) {
|
||||
values[i] |= gainValue;
|
||||
FILE_LOG(logDEBUG1, ("Value %d: 0x%x\n", i, values[i]));
|
||||
}
|
||||
}
|
||||
// create command
|
||||
const int lenAduBits = ASIC_GAIN_MAX_BITS + ADU_MAX_BITS;
|
||||
const int lenBits = lenAduBits * NCHAN;
|
||||
const int len = lenBits / 8;
|
||||
char buffer[len];
|
||||
memset(buffer, 0, len);
|
||||
int iBit = 4; // 4 due to padding
|
||||
int ich = 0;
|
||||
for (ich = 0; ich < NCHAN; ++ich) {
|
||||
// copy 14 bits for each channel
|
||||
int totalToCopy = lenAduBits;
|
||||
while (totalToCopy > 0) {
|
||||
int byteIndex = iBit / 8;
|
||||
int bitIndex = iBit % 8;
|
||||
// how much to copy in a byte
|
||||
int toCopy = 8 - bitIndex;
|
||||
if (toCopy > totalToCopy) {
|
||||
toCopy = totalToCopy;
|
||||
}
|
||||
int copyMask = (1 << toCopy) - 1;
|
||||
// value pushed out by whats left and masked
|
||||
int val = (values[ich] >> (totalToCopy - toCopy)) & copyMask;
|
||||
if (toCopy + bitIndex != 8) {
|
||||
val = val << (8 - bitIndex - toCopy);
|
||||
}
|
||||
buffer[byteIndex] |= val;
|
||||
// incrememnt indices
|
||||
iBit += toCopy;
|
||||
totalToCopy -= toCopy;
|
||||
}
|
||||
}
|
||||
|
||||
// address at the end
|
||||
buffer[16] |= (ASIC_VETO_REF_ADDR);
|
||||
|
||||
if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// all chips
|
||||
if (chipIndex == -1) {
|
||||
int ichip = 0;
|
||||
int ichan = 0;
|
||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
||||
for (ichip = 0; ichip < NCHIP; ++ichip) {
|
||||
vetoReference[ichip][ichan] = values[ichan];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// specific chip
|
||||
else {
|
||||
int ichan = 0;
|
||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
||||
vetoReference[chipIndex][chipIndex] = values[ichan];;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getVetoPhoton(int chipIndex, int* retvals) {
|
||||
if (chipIndex == -1) {
|
||||
int i = 0, j = 0;
|
||||
for (i = 0; i < NCHAN; ++i) {
|
||||
int val = vetoReference[0][i];
|
||||
for (j = 1; j < NCHIP; ++j) {
|
||||
if (vetoReference[j][i] != val) {
|
||||
FILE_LOG(logERROR, ("Get vet photon fail for chipIndex:%d. Different values between [nchip:%d, nchan:%d, value:%d] and [nchip:0, nchan:%d, value:%d]\n", chipIndex, j, i, vetoReference[j][i], i, val));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
chipIndex = 0;
|
||||
}
|
||||
memcpy((char*)retvals, ((char*)vetoReference) + NCHAN * chipIndex * sizeof(int), sizeof(int) * NCHAN);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* aquisition */
|
||||
|
@ -19,6 +19,9 @@
|
||||
#define CONFIG_FILE ("config.txt")
|
||||
#define DAC_MAX_MV (2048)
|
||||
#define ONCHIP_DAC_MAX_VAL (0x3FF)
|
||||
#define ADU_MAX_VAL (0xFFF)
|
||||
#define ADU_MAX_BITS (12)
|
||||
|
||||
|
||||
/** Default Parameters */
|
||||
#define DEFAULT_NUM_FRAMES (1)
|
||||
@ -38,7 +41,6 @@
|
||||
#define READOUT_PLL_VCO_FREQ_HZ (866666688) // Hz
|
||||
#define SYSTEM_PLL_VCO_FREQ_HZ (722222240) // Hz
|
||||
|
||||
|
||||
/** Other Definitions */
|
||||
#define BIT16_MASK (0xFFFF)
|
||||
|
||||
@ -81,7 +83,13 @@ enum PLLINDEX {READOUT_PLL, SYSTEM_PLL};
|
||||
|
||||
/** Chip Definitions */
|
||||
#define ASIC_CURRENT_INJECT_ADDR (0x9)
|
||||
#define ASIC_VETO_REF_ADDR (0xA)
|
||||
#define ASIC_GAIN_MAX_BITS (2)
|
||||
#define ASIC_GAIN_MSK (0x3)
|
||||
|
||||
#define ASIC_G0_VAL ((0x0 & ASIC_GAIN_MSK) << ADU_MAX_BITS)
|
||||
#define ASIC_G1_VAL ((0x1 & ASIC_GAIN_MSK) << ADU_MAX_BITS)
|
||||
#define ASIC_G2_VAL ((0x3 & ASIC_GAIN_MSK) << ADU_MAX_BITS)
|
||||
|
||||
/* Struct Definitions */
|
||||
typedef struct udp_header_struct {
|
||||
|
@ -450,6 +450,8 @@ int setClockDivider(enum CLKINDEX ind, int val);
|
||||
int getClockDivider(enum CLKINDEX ind);
|
||||
int setInjectChannel(int offset, int increment);
|
||||
void getInjectedChannels(int* offset, int* increment);
|
||||
int setVetoPhoton(int chipIndex, int gainIndex, int* values);
|
||||
int getVetoPhoton(int chipIndex, int* retvals);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -196,4 +196,6 @@ int get_pipeline(int);
|
||||
int set_on_chip_dac(int);
|
||||
int get_on_chip_dac(int);
|
||||
int set_inject_channel(int);
|
||||
int get_inject_channel(int);
|
||||
int get_inject_channel(int);
|
||||
int set_veto_photon(int);
|
||||
int get_veto_photon(int);
|
@ -83,8 +83,8 @@ int ALTERA_PLL_C10_GetMaxPhaseShiftStepsofVCO() {
|
||||
|
||||
int ALTERA_PLL_C10_Reconfigure(int pllIndex) {
|
||||
FILE_LOG(logINFO, ("\tReconfiguring PLL %d\n", pllIndex));
|
||||
uint32_t waitreg = ALTERA_PLL_C10_Wait_Reg[pllIndex];
|
||||
uint32_t waitmsk = ALTERA_PLL_C10_Wait_Msk[pllIndex];
|
||||
//uint32_t waitreg = ALTERA_PLL_C10_Wait_Reg[pllIndex];
|
||||
//uint32_t waitmsk = ALTERA_PLL_C10_Wait_Msk[pllIndex];
|
||||
|
||||
// write anything to base address to start reconfiguring
|
||||
FILE_LOG(logDEBUG1, ("\tWriting 1 to base address 0x%x to start reconfiguring\n", ALTERA_PLL_C10_BaseAddress[pllIndex]));
|
||||
@ -115,8 +115,8 @@ int ALTERA_PLL_C10_Reconfigure(int pllIndex) {
|
||||
|
||||
void ALTERA_PLL_C10_ResetPLL (int pllIndex) {
|
||||
FILE_LOG(logINFO, ("Resetting PLL %d\n", pllIndex));
|
||||
uint32_t resetreg = ALTERA_PLL_C10_Reset_Reg[pllIndex];
|
||||
uint32_t resetmsk = ALTERA_PLL_C10_Reset_Msk[pllIndex];
|
||||
//uint32_t resetreg = ALTERA_PLL_C10_Reset_Reg[pllIndex];
|
||||
//uint32_t resetmsk = ALTERA_PLL_C10_Reset_Msk[pllIndex];
|
||||
|
||||
FILE_LOG(logERROR, ("Reset not implemented yet!\n"));
|
||||
/* TODO reset reg and reset mask to be done in firware, so wait instead (above)
|
||||
|
@ -298,6 +298,8 @@ const char* getFunctionName(enum detFuncs func) {
|
||||
case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC";
|
||||
case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL";
|
||||
case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL";
|
||||
case F_SET_VETO_PHOTON: return "F_SET_VETO_PHOTON";
|
||||
case F_GET_VETO_PHOTON: return "F_GET_VETO_PHOTON";
|
||||
|
||||
default: return "Unknown Function";
|
||||
}
|
||||
@ -473,7 +475,9 @@ void function_table() {
|
||||
flist[F_GET_ON_CHIP_DAC] = &get_on_chip_dac;
|
||||
flist[F_SET_INJECT_CHANNEL] = &set_inject_channel;
|
||||
flist[F_GET_INJECT_CHANNEL] = &get_inject_channel;
|
||||
|
||||
flist[F_SET_VETO_PHOTON] = &set_veto_photon;
|
||||
flist[F_GET_VETO_PHOTON] = &get_veto_photon;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
FILE_LOG(logERROR, ("The last detector function enum has reached its limit\nGoodbye!\n"));
|
||||
@ -6176,7 +6180,6 @@ int set_inject_channel(int file_des) {
|
||||
} else {
|
||||
ret = setInjectChannel(offset, increment);
|
||||
if (ret == FAIL) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Could not inject channel\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
@ -6206,3 +6209,102 @@ int get_inject_channel(int file_des) {
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, retvals, sizeof(retvals));
|
||||
}
|
||||
|
||||
|
||||
int set_veto_photon(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int args[3] = {-1, -1, -1};
|
||||
|
||||
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
int values[args[2]];
|
||||
if (receiveData(file_des, values, sizeof(values), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logINFO, ("Setting Veto Photon: [chipIndex:%d, G%d, nch:%d]\n", args[0], args[1], args[2]));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
int chipIndex = args[0];
|
||||
int gainIndex = args[1];
|
||||
int numChannels = args[2];
|
||||
if (chipIndex < -1 || chipIndex >= NCHIP) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set veto photon. Invalid chip index %d\n", chipIndex);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else if (gainIndex < 0 || gainIndex > 2) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set veto photon. Invalid gain index %d\n", gainIndex);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else if (numChannels != NCHAN) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set veto photon. Invalid number of channels %d. Expected %d\n", numChannels, NCHAN);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
int i = 0;
|
||||
for (i = 0; i < NCHAN; ++i) {
|
||||
if (values[i] > ADU_MAX_VAL) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set veto photon. Invalid ADU value 0x%x for channel %d, must be 12 bit.\n", i, values[i]);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret == OK) {
|
||||
ret = setVetoPhoton(chipIndex, gainIndex, values);
|
||||
if (ret == FAIL) {
|
||||
sprintf(mess, "Could not set veto photon for chip index %d\n", chipIndex);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
int get_veto_photon(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int arg = -1;
|
||||
int retvals[NCHAN];
|
||||
memset(retvals, 0, sizeof(retvals));
|
||||
|
||||
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Getting veto photon [chip Index:%d]\n", arg));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get only
|
||||
int chipIndex = arg;
|
||||
if (chipIndex < -1 || chipIndex >= NCHIP) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not get veto photon. Invalid chip index %d\n", chipIndex);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
ret = getVetoPhoton(chipIndex, retvals);
|
||||
if (ret == FAIL) {
|
||||
strcpy(mess, "Could not get veto photon for chipIndex -1. Not the same for all chips.\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
int i = 0;
|
||||
for (i = 0; i < NCHAN; ++i) {
|
||||
FILE_LOG(logDEBUG1, ("%d:0x%x\n", i, retvals[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
|
||||
if (ret != FAIL) {
|
||||
int nch = NCHAN;
|
||||
sendData(file_des, &nch, sizeof(nch), INT32);
|
||||
sendData(file_des, retvals, sizeof(retvals), INT32);
|
||||
}
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user