Files
maliakal_dandGitHub 8f07d2a464
Build on RHEL9 / build (push) Successful in 3m46s
Run Simulator Tests on local RHEL9 / build (push) Failing after 3m51s
Build on RHEL8 / build (push) Successful in 5m15s
Run Simulator Tests on local RHEL8 / build (push) Failing after 5m31s
Build on local RHEL8 / build (push) Failing after 3m31s
Build on local RHEL9 / build (push) Failing after 1m25s
Dev/xilinx set dac rewrite (#1389)
* wip

* wip

* wip. xilinx left

* wip. xilinx

* wip

* wip. compiles

* fixed eiger test

* more fixes

* fixed virtual m3

* fix typos and bugs

* setting power to 0

* set power fixed

* updated server binaries

* minor

* refactoring

* get vchip refactoring

* eiger: unnecessary check for setsettings undefined

* retval pointer for printout

* eiger.wip, mV in boolean

* wip. gotthard2 and m3

* wip. jungfrau

* moench.wip

* compiles.wip

* fix eiger

* m3 fix vthresh

* fix ctband xilinx

* default pwr index = pwr_io

* minor:fn name and highvoltage to local var

* refactor funcs

* minor

* minor

* check dac voltage only for normal dacs and not for power dacs as the dac voltage range is different for ctb and xilinx ctb, also throw for -1 in set for set_dac in client itself. in the server its not clear if its set or get with a -1

* minor

* updated versioning

* review changes: removing validateDACValue and other minor stuff

* binaries in

* wip

* refactored m3 vth

* minor review

* minor review

* m3 serverdac index fix

* minor
2026-02-23 14:23:13 +01:00

118 lines
3.2 KiB
C

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "DAC6571.h"
#include "clogger.h"
#include "common.h"
#include "sls/sls_detector_defs.h"
#include "string.h"
/* DAC6571 HV DEFINES */
#define DAC6571_MIN_DAC_VAL (0x0)
#define DAC6571_MAX_DAC_VAL (0x3FF)
// defines from the hardware
int DAC6571_HardMaxVoltage = 0;
char DAC6571_DriverFileName[MAX_STR_LENGTH];
#ifdef VIRTUAL
int highvoltage = 0;
#endif
void DAC6571_SetDefines(int hardMaxV, char *driverfname) {
LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n",
driverfname, hardMaxV));
DAC6571_HardMaxVoltage = hardMaxV;
memset(DAC6571_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(DAC6571_DriverFileName, driverfname);
#ifdef VIRTUAL
highvoltage = 0;
#endif
}
int DAC6571_Set(int val, char *mess) {
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0) {
sprintf(mess, "Invalid value. Cannot be negative.\n");
LOG(logERROR, (mess));
return FAIL;
}
int dacvalue = 0;
// convert value
if (ConvertToDifferentRange(0, DAC6571_HardMaxVoltage, DAC6571_MIN_DAC_VAL,
DAC6571_MAX_DAC_VAL, val, &dacvalue) == FAIL) {
sprintf(mess,
"Could not convert %d high voltage to a valid dac value\n",
val);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
#ifdef VIRTUAL
highvoltage = dacvalue;
#else
// open file
FILE *fd = fopen(DAC6571_DriverFileName, "w");
if (fd == NULL) {
sprintf(mess,
"Could not open file %s for writing to set high voltage\n",
DAC6571_DriverFileName);
LOG(logERROR, (mess));
return FAIL;
}
// convert to string, add 0 and write to file
fprintf(fd, "%d\n", dacvalue);
fclose(fd);
#endif
return OK;
}
int DAC6571_Get(int *retval, char *mess) {
LOG(logDEBUG1, ("Getting high voltage\n"));
int dacvalue = 0;
#ifdef VIRTUAL
dacvalue = highvoltage;
#else
if (readParameterFromFile(DAC6571_DriverFileName, "high voltage",
&dacvalue) == FAIL) {
sprintf(mess, "Could not get high voltage\n");
LOG(logERROR, (mess));
return FAIL;
}
#endif
// convert value
if (ConvertToDifferentRange(DAC6571_MIN_DAC_VAL, DAC6571_MAX_DAC_VAL, 0,
DAC6571_HardMaxVoltage, dacvalue,
retval) == FAIL) {
sprintf(mess,
"Could not convert %d dac value to a valid high voltage\n",
dacvalue);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\t%dV (dacval %d)\n", (*retval), dacvalue));
#ifndef VIRTUAL
// open file
FILE *fd = fopen(DAC6571_DriverFileName, "w");
if (fd == NULL) {
sprintf(mess,
"Could not open file %s for writing to get high voltage\n",
DAC6571_DriverFileName);
LOG(logERROR, (mess));
return FAIL;
}
// convert to string, add 0 and write to file
fprintf(fd, "%d\n", dacvalue);
fclose(fd);
#endif
return OK;
}