eiger.wip, mV in boolean

This commit is contained in:
2026-02-11 16:03:58 +01:00
parent 61a4bbfb0c
commit 2efce1203d
8 changed files with 169 additions and 117 deletions
@@ -880,7 +880,7 @@ int resetToDefaultDacs(int hardReset, char *mess) {
int ret = OK;
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
for (int i = 0; i < NDAC; ++i) {
if (setDAC((enum DACINDEX)i, defaultDacValues[i], 0, mess) == FAIL)
if (setDAC((enum DACINDEX)i, defaultDacValues[i], false, mess) == FAIL)
return FAIL;
}
return ret;
@@ -1330,7 +1330,7 @@ int setModule(sls_detector_module myMod, char *mess) {
// dacs
for (int i = 0; i < NDAC; ++i) {
if (setDAC((enum DACINDEX)i, myMod.dacs[i], 0, mess) == FAIL)
if (setDAC((enum DACINDEX)i, myMod.dacs[i], false, mess) == FAIL)
return FAIL;
if (myMod.dacs[i] != (detectorModules)->dacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
@@ -1427,144 +1427,183 @@ int setThresholdEnergy(int ev) {
}
/* parameters - dac, adc, hv */
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
char *dacNames[] = {DAC_NAMES};
// validate index (including E_VTHRESHOLD)
int validateDACIndex(enum DACINDEX ind, char *mess) {
// including E_VTHRESHOLD
if (ind < 0 || ind >= NDAC + 1) {
sprintf(mess, "Could not set DAC. Invalid index %d\n", ind);
LOG(logERROR, (mess));
return FAIL;
}
// validate min value
if (val < 0) {
sprintf(mess,
"Could not set DAC %s. Input value %d cannot be negative\n",
dacNames[ind], val);
LOG(logERROR, (mess));
return FAIL;
}
// validate max value
if (mV && val > DAC_MAX_MV) {
sprintf(mess,
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
dacNames[ind], val, DAC_MAX_MV);
LOG(logERROR, (mess));
return FAIL;
} else if (!mV && val > LTC2620_MAX_VAL) {
sprintf(mess,
"Could not set DAC %s. Input value %d exceed maximum %d \n",
dacNames[ind], val, LTC2620_MAX_VAL);
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}
// uses LTC2620 with 2.048V (implementation different to others not bit banging)
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
if (validateDAC(ind, val, mV, mess) == FAIL)
int validateDACValue(enum DACINDEX ind, int dacval, char *mess) {
char *dacNames[] = {DAC_NAMES};
if (dacval < 0) {
sprintf(mess,
"Could not set DAC %s. Input value %d cannot be negative\n",
dacNames[ind], dacval);
LOG(logERROR, (mess));
return FAIL;
}
// validate max value
if (dacval > LTC2620_MAX_VAL) {
sprintf(mess,
"Could not set DAC %s. Input value %d exceed maximum %d \n",
dacNames[ind], dacval, LTC2620_MAX_VAL);
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}
int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess) {
char *dacNames[] = {DAC_NAMES};
// validate min value
if (voltage < 0) {
sprintf(mess,
"Could not set DAC %s. Input value %d cannot be negative\n",
dacNames[ind], voltage);
LOG(logERROR, (mess));
return FAIL;
}
// validate max value
if (voltage > DAC_MAX_MV) {
sprintf(mess,
"Could not set DAC %s. Input value %d mV exceed maximum %d mV\n", dacNames[ind], voltage, DAC_MAX_MV);
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}
int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int* retval_dacval, char *mess) {
char *dacNames[] = {DAC_NAMES};
if (ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL, LTC2620_MAX_VAL, voltage, retval_dacval) == FAIL) {
sprintf(
mess,
"Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], voltage);
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}
int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int* retval_voltage, char *mess) {
*retval_voltage = -1;
if (ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV,
DAC_MAX_MV, dacval, retval_voltage) == FAIL) {
char *dacNames[] = {DAC_NAMES};
sprintf(mess,
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
dacNames[ind], dacval);
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}
int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess) {
if (ind == E_VTHRESHOLD) {
return getThresholdDACs(mV, retval, mess);
}
if (validateDACIndex(ind, mess) == FAIL)
return FAIL;
int dacval = (detectorModules)->dacs[ind];
if (mV) {
if (convertDACValueToVoltage(ind, dacval, retval, mess) == FAIL)
return FAIL;
return OK;
}
*retval = dacval;
return OK;
}
// uses LTC2620 with 2.048V (implementation different to others not bit banging)
int setDAC(enum DACINDEX ind, int val, bool mV, char *mess) {
char *dacNames[] = {DAC_NAMES};
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
(mV ? "mV" : "dac units")));
if (ind == E_VTHRESHOLD) {
if (setDAC(E_VCMP_LL, val, mV, mess) == FAIL)
return FAIL;
if (setDAC(E_VCMP_LR, val, mV, mess) == FAIL)
return FAIL;
if (setDAC(E_VCMP_RL, val, mV, mess) == FAIL)
return FAIL;
if (setDAC(E_VCMP_RR, val, mV, mess) == FAIL)
return FAIL;
if (setDAC(E_VCP, val, mV, mess) == FAIL)
return FAIL;
return OK;
return setThresholdDACs(val, mV, mess);
}
// mV: convert to dac value
if (validateDACIndex(ind, mess) == FAIL)
return FAIL;
int dacval = val;
if (mV) {
if (ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL,
LTC2620_MAX_VAL, val, &dacval) == FAIL) {
sprintf(
mess,
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
dacNames[ind], val);
LOG(logERROR, (mess));
if (validateDACVoltage(ind, val, mess) == FAIL)
return FAIL;
if (convertVoltageToDACValue(ind, val, &dacval, mess) == FAIL)
return FAIL;
}
}
#ifdef VIRTUAL
(detectorModules)->dacs[ind] = dacval;
#else
sharedMemory_lockLocalLink();
if (Feb_Control_SetDAC(ind, dacval)) {
(detectorModules)->dacs[ind] = dacval;
}
sharedMemory_unlockLocalLink();
#endif
if (writeDACSpi(ind, dacval, mess) == FAIL)
return FAIL;
return OK;
}
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
// validate index (including E_VTHRESHOLD)
if (ind < 0 || ind >= NDAC + 1) {
sprintf(mess, "Could not set DAC. Invalid index %d\n", ind);
int writeDACSpi(enum DACINDEX ind, int dacval, char *mess) {
if (validateDACValue(ind, dacval, mess) == FAIL)
return FAIL;
#ifdef VIRTUAL
(detectorModules)->dacs[ind] = dacval;
return OK;
#else
sharedMemory_lockLocalLink();
if (!Feb_Control_SetDAC(ind, dacval)) {
char *dacNames[] = {DAC_NAMES};
sprintf(mess, "Could not set DAC %s. Trouble writing to register\n", dacNames[ind]);
LOG(logERROR, (mess));
sharedMemory_unlockLocalLink();
return FAIL;
}
(detectorModules)->dacs[ind] = dacval;
sharedMemory_unlockLocalLink();
return OK;
#endif
}
if (ind == E_VTHRESHOLD) {
int retvals[5] = {0};
if (getDAC(E_VCMP_LL, mV, &retvals[0], mess) == FAIL)
return FAIL;
if (getDAC(E_VCMP_LR, mV, &retvals[1], mess) == FAIL)
return FAIL;
if (getDAC(E_VCMP_RL, mV, &retvals[2], mess) == FAIL)
return FAIL;
if (getDAC(E_VCMP_RR, mV, &retvals[3], mess) == FAIL)
return FAIL;
if (getDAC(E_VCP, mV, &retvals[4], mess) == FAIL)
return FAIL;
if ((retvals[0] != retvals[1]) || (retvals[1] != retvals[2]) ||
(retvals[2] != retvals[3]) || (retvals[3] != retvals[4])) {
LOG(logWARNING,
("Vthreshold mismatch. vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d "
"vcmp_rr:%d vcp:%d\n",
retvals[0], retvals[1], retvals[2], retvals[3], retvals[4]));
int setThresholdDACs(int val, bool mV, char *mess) {
enum DACINDEX indices[5] = {E_VCMP_LL, E_VCMP_LR, E_VCMP_RL, E_VCMP_RR, E_VCP};
for (int i = 1; i != 5; ++i) {
if (setDAC(indices[i], val, mV, mess) == FAIL)
return FAIL;
}
return OK;
}
int getThresholdDACs(bool mV, int *retval, char *mess) {
enum DACINDEX indices[5] = {E_VCMP_LL, E_VCMP_LR, E_VCMP_RL, E_VCMP_RR, E_VCP};
int retvals[5] = {0};
if (getDAC(indices[0], mV, &retvals[0], mess) == FAIL)
return FAIL;
bool allEqual = true;
for (int i = 1; i != 5; ++i) {
if (getDAC(indices[i], mV, &retvals[i], mess) == FAIL)
return FAIL;
if (retvals[i] != retvals[0]) {
char *dacNames[] = {DAC_NAMES};
LOG(logWARNING, ("Vthreshold mismatch.%s:%d %s:%d\n", dacNames[indices[i]], retvals[i], dacNames[indices[0]], retvals[0]));
*retval = -1;
return OK;
}
*retval = retvals[0];
LOG(logINFO, ("\tvthreshold match %d\n", *retval));
return OK;
}
char *dacNames[] = {DAC_NAMES};
if (!mV) {
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind],
(detectorModules)->dacs[ind]));
*retval = (detectorModules)->dacs[ind];
return OK;
}
// convert to mV
*retval = -1;
if (ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV,
DAC_MAX_MV, (detectorModules)->dacs[ind],
retval) == FAIL) {
sprintf(mess,
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
dacNames[ind], (detectorModules)->dacs[ind]);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
(detectorModules)->dacs[ind], *retval));
*retval = retvals[0];
LOG(logINFO, ("\tvthreshold match %d\n", *retval));
return OK;
}
@@ -6,6 +6,7 @@
#include <stdio.h> // FILE
#include <stdlib.h>
#include <sys/types.h>
#include <stdbool.h>
/****************************************************
This functions are used by the slsDetectroServer_funcs interface.
@@ -123,9 +124,19 @@ int getThresholdEnergy();
int setThresholdEnergy(int ev);
// parameters - dac, adc, hv
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
int validateDACIndex(enum DACINDEX ind, char *mess);
int validateDACValue(enum DACINDEX ind, int dacval, char *mess);
int validateDACVoltage(enum DACINDEX ind, int voltage, char *mess);
int convertVoltageToDACValue(enum DACINDEX ind, int voltage, int* retval_dacval, char *mess);
int convertDACValueToVoltage(enum DACINDEX ind, int dacval, int* retval_voltage, char *mess);
int getDAC(enum DACINDEX ind, bool mV, int *retval, char *mess);
/** @param val value can be in mV or dac units */
int setDAC(enum DACINDEX ind, int val, bool mV, char *mess);
/** @param dacval in dac units */
int writeDACSpi(enum DACINDEX ind, int dacval, char *mess);
int setThresholdDACs(int val, bool mV, char *mess);
int getThresholdDACs(bool mV, int *retval, char *mess);
int getADC(enum ADCINDEX ind);
int setHighVoltage(int val, char *mess);
@@ -3,6 +3,7 @@
#pragma once
#include <inttypes.h>
#include <stdbool.h>
#ifdef JUNGFRAUD
void AD9257_Set_Jungfrau_Hardware_Version_1_0(int val);
@@ -27,7 +28,7 @@ void AD9257_Disable();
/**
* Get vref voltage
*/
int AD9257_GetVrefVoltage(int mV);
int AD9257_GetVrefVoltage(bool mV);
/**
* Set vref voltage
@@ -35,7 +36,7 @@ int AD9257_GetVrefVoltage(int mV);
* for 1.6V, 4 for 2.0V
* @returns ok or fail
*/
int AD9257_SetVrefVoltage(int val, int mV);
int AD9257_SetVrefVoltage(int val, bool mV);
/**
* Set SPI reg value
@@ -4,6 +4,7 @@
#include "clogger.h"
#include "common.h"
#include "sls/sls_detector_defs.h"
#include <stdbool.h>
#define GOODBYE (-200)
#define REBOOT (-400)
@@ -39,7 +40,7 @@ int set_bus_test(int);
int set_image_test_mode(int);
int get_image_test_mode(int);
enum DACINDEX getDACIndex(enum dacIndex ind);
int validateAndSetDac(enum dacIndex ind, int val, int mV);
int validateAndSetDac(enum dacIndex ind, int val, bool mV);
int set_dac(int);
int get_adc(int);
int write_register(int);
@@ -195,7 +195,7 @@ void AD9257_Disable() {
}
int AD9257_GetVrefVoltage(int mV) {
if (mV == 0)
if (!mV)
return AD9257_VrefVoltage;
switch (AD9257_VrefVoltage) {
case 0:
@@ -1159,7 +1159,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) {
return serverDacIndex;
}
int validateAndSetDac(enum dacIndex ind, int val, int mV) {
int validateAndSetDac(enum dacIndex ind, int val, bool mV) {
int retval = -1;
enum DACINDEX serverDacIndex = 0;
@@ -1305,7 +1305,7 @@ int set_dac(int file_des) {
return printSocketReadError();
enum dacIndex ind = args[0];
int mV = args[1];
bool mV = (args[1] != 0);
int val = args[2];
LOG(logDEBUG1,
@@ -1944,7 +1944,7 @@ void *start_state_machine(void *arg) {
else {
LOG(logINFOBLUE, ("Dac [%d] scan %d/%d: [%d]\n",
scanGlobalIndex, i, times, scanSteps[i]));
validateAndSetDac(scanGlobalIndex, scanSteps[i], 0);
validateAndSetDac(scanGlobalIndex, scanSteps[i], false);
if (ret == FAIL) {
sprintf(scanErrMessage, "Cannot scan dac %d at %d. ",
scanGlobalIndex, scanSteps[i]);
+1 -1
View File
@@ -6,7 +6,7 @@
#define APICTB "0.0.0 0x260210"
#define APIGOTTHARD2 "0.0.0 0x260210"
#define APIMOENCH "0.0.0 0x260210"
#define APIEIGER "0.0.0 0x260210"
#define APIEIGER "0.0.0 0x260211"
#define APIXILINXCTB "0.0.0 0x260210"
#define APIJUNGFRAU "0.0.0 0x260210"
#define APIMYTHEN3 "0.0.0 0x260210"