mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-22 05:54:29 +01:00
refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
|
|
||||||
void XILINX_FMC_enable_all();
|
int XILINX_FMC_enable_all(char* error_message, int message_size);
|
||||||
void XILINX_FMC_disable_all();
|
int XILINX_FMC_disable_all(char* error_message, int message_size);
|
||||||
@@ -24,41 +24,56 @@ static const char *fmc_files[] = {
|
|||||||
FMC_12V_EN,
|
FMC_12V_EN,
|
||||||
FMCP_12V_EN
|
FMCP_12V_EN
|
||||||
};
|
};
|
||||||
|
#define FMC_NUM_FILES (sizeof(fmc_files) / sizeof(fmc_files[0]))
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
void XILINX_FMC_enable_all() {
|
int XILINX_FMC_enable_all(char* error_message, int message_size) {
|
||||||
LOG(logINFOBLUE, ("enable FMC power\n"));
|
LOG(logINFOBLUE, ("enable FMC power\n"));
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
char full_path[64];
|
char full_path[64];
|
||||||
for (size_t i = 0; i < sizeof(fmc_files) / sizeof(fmc_files[0]); ++i) {
|
for (size_t i = 0; i < FMC_NUM_FILES; ++i) {
|
||||||
snprintf(full_path, sizeof(full_path), "%s%s", FMC_BASE_PATH, fmc_files[i]);
|
const char* file = fmc_files[i];
|
||||||
|
snprintf(full_path, sizeof(full_path), "%s%s", FMC_BASE_PATH, file);
|
||||||
FILE *fp = fopen(full_path, "w");
|
FILE *fp = fopen(full_path, "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
LOG(logERROR,("XILINX_FMC: enable Error\n"));
|
snprintf(error_message, message_size, "XILINX_FMC: Couuld not enable.\n");
|
||||||
continue;
|
LOG(logERROR, (error_message));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "1\n");
|
if (fprintf(fp, "1\n") != 1) {
|
||||||
|
snprintf(error_message, message_size, "XILINX_FMC: Could not write enable.\n");
|
||||||
|
LOG(logERROR, (error_message));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XILINX_FMC_disable_all() {
|
int XILINX_FMC_disable_all(char* error_message, int message_size) {
|
||||||
LOG(logINFOBLUE, ("disable FMC power\n"));
|
LOG(logINFOBLUE, ("disable FMC power\n"));
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
char full_path[64];
|
char full_path[64];
|
||||||
for (size_t i = 0; i < sizeof(fmc_files) / sizeof(fmc_files[0]); ++i) {
|
for (size_t i = 0; i < FMC_NUM_FILES; ++i) {
|
||||||
snprintf(full_path, sizeof(full_path), "%s%s", FMC_BASE_PATH, fmc_files[i]);
|
const char* file = fmc_files[i];
|
||||||
|
snprintf(full_path, sizeof(full_path), "%s%s", FMC_BASE_PATH, file);
|
||||||
FILE *fp = fopen(full_path, "w");
|
FILE *fp = fopen(full_path, "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
LOG(logERROR,("XILINX_FMC: disable Error\n"));
|
snprintf(error_message, message_size, "XILINX_FMC: Could not disable\n");
|
||||||
continue;
|
LOG(logERROR, (error_message));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (fprintf(fp, "0\n") != 1) {
|
||||||
|
snprintf(error_message, message_size, "XILINX_FMC: Could not write disable.\n");
|
||||||
|
LOG(logERROR, (error_message));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
fprintf(fp, "0\n");
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -407,7 +407,10 @@ void setupDetector() {
|
|||||||
NPWR, DAC_POWERDOWN_DRIVER_FILE_NAME);
|
NPWR, DAC_POWERDOWN_DRIVER_FILE_NAME);
|
||||||
|
|
||||||
// power LTC2620 before talking to it:
|
// power LTC2620 before talking to it:
|
||||||
XILINX_FMC_enable_all();
|
initError = XILINX_FMC_enable_all(initErrorMessage, MAX_STR_LENGTH);
|
||||||
|
if (initError == FAIL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG(logINFOBLUE, ("Powering down all dacs\n"));
|
LOG(logINFOBLUE, ("Powering down all dacs\n"));
|
||||||
for (int idac = 0; idac < NDAC; ++idac) {
|
for (int idac = 0; idac < NDAC; ++idac) {
|
||||||
@@ -583,10 +586,10 @@ int powerChip(int on, char *mess) {
|
|||||||
} else {
|
} else {
|
||||||
LOG(logINFOBLUE, ("Powering chip: off\n"));
|
LOG(logINFOBLUE, ("Powering chip: off\n"));
|
||||||
bus_w(addr, bus_r(addr) & ~mask);
|
bus_w(addr, bus_r(addr) & ~mask);
|
||||||
XILINX_FMC_disable_all();
|
|
||||||
|
|
||||||
chipConfigured = 0;
|
chipConfigured = 0;
|
||||||
|
if (FAIL == XILINX_FMC_disable_all(mess, MAX_STR_LENGTH)) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
setTransceiverAlignment(0);
|
setTransceiverAlignment(0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user