mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-21 03:08:41 +01:00
more fixes
This commit is contained in:
@@ -1940,13 +1940,14 @@ int setHighVoltage(int val, char *mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
LOG(logINFO, ("Setting High voltage: %d V\n", val));
|
||||
uint32_t addr = POWER_REG;
|
||||
|
||||
// switch to external high voltage
|
||||
bus_w(addr, bus_r(addr) & (~POWER_HV_INTERNAL_SLCT_MSK));
|
||||
|
||||
MAX1932_Set(&val);
|
||||
if (MAX1932_Set(val, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
// switch on internal high voltage, if set
|
||||
if (val > 0)
|
||||
@@ -1958,7 +1959,8 @@ int setHighVoltage(int val, char *mess) {
|
||||
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
*retval = highvoltage;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
@@ -1539,7 +1539,10 @@ int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
|
||||
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]));
|
||||
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]));
|
||||
*retval = -1;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1474,20 +1474,17 @@ int getADC(enum ADCINDEX ind) {
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
LOG(logINFO, ("Setting High voltage: %d V\n", val));
|
||||
if (MAX1932_Set(val, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
MAX1932_Set(&val);
|
||||
highvoltage = val;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
*retval = highvoltage;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
@@ -1040,20 +1040,17 @@ int getADC(enum ADCINDEX ind) {
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
LOG(logINFO, ("Setting High voltage: %d V\n", val));
|
||||
if (MAX1932_Set(val, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
MAX1932_Set(&val);
|
||||
highvoltage = val;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
*retval = highvoltage;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
@@ -1715,7 +1715,8 @@ int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
}
|
||||
// different values for enabled counters
|
||||
else if (retval1 != *retval) {
|
||||
LOG(logWARNING,("Could not get threhsold dac. Different values for enabled counters.\n"));
|
||||
LOG(logWARNING, ("Could not get threhsold dac. Different "
|
||||
"values for enabled counters.\n"));
|
||||
*retval = -1;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -17,14 +17,5 @@
|
||||
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk,
|
||||
uint32_t dmsk, int dofst, int minMV, int maxMV);
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
void MAX1932_Disable();
|
||||
|
||||
/**
|
||||
* Set value (value is updated to correct range)
|
||||
* @param val pointer to value to set
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int MAX1932_Set(int *val);
|
||||
int MAX1932_Set(int val, char *mess);
|
||||
|
||||
@@ -43,33 +43,33 @@ void MAX1932_Disable() {
|
||||
~(MAX1932_DigMask));
|
||||
}
|
||||
|
||||
int MAX1932_Set(int *val) {
|
||||
LOG(logDEBUG1, ("Setting high voltage to %d\n", *val));
|
||||
if (*val < 0)
|
||||
return FAIL;
|
||||
|
||||
int dacvalue = 0;
|
||||
int MAX1932_Set(int val, char *mess) {
|
||||
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
|
||||
|
||||
// limit values (normally < 60 => 0 (off))
|
||||
if (*val < MAX1932_MinVoltage) {
|
||||
if ((val != 0 && val < MAX1932_MinVoltage) || val > MAX1932_MaxVoltage) {
|
||||
sprintf(mess,
|
||||
"Could not set high voltage. Invalid value:%d. Should bet be 0 "
|
||||
"or between %d and %d\n",
|
||||
val, MAX1932_MinVoltage, MAX1932_MaxVoltage);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
int dacvalue = 0;
|
||||
if (val == 0)
|
||||
dacvalue = MAX1932_POWER_OFF_DAC_VAL;
|
||||
*val = 0;
|
||||
else if (ConvertToDifferentRange(MAX1932_MinVoltage, MAX1932_MaxVoltage,
|
||||
MAX1932_MIN_DAC_VAL, MAX1932_MAX_DAC_VAL,
|
||||
val, &dacvalue) == FAIL) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set high voltage %d. Could not convert to dac units\n",
|
||||
val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// limit values (normally > 200 => 0x1 (max))
|
||||
else if (*val > MAX1932_MaxVoltage) {
|
||||
dacvalue = MAX1932_MAX_DAC_VAL;
|
||||
*val = MAX1932_MaxVoltage;
|
||||
}
|
||||
// convert value
|
||||
else {
|
||||
// no failure in conversion as limits handled (range from 0x1 to 0xFF)
|
||||
ConvertToDifferentRange(MAX1932_MinVoltage, MAX1932_MaxVoltage,
|
||||
MAX1932_MIN_DAC_VAL, MAX1932_MAX_DAC_VAL, *val,
|
||||
&dacvalue);
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
}
|
||||
|
||||
LOG(logINFO, ("\t%dV (dacval %d)\n", *val, dacvalue));
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
|
||||
serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS,
|
||||
MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset, 0);
|
||||
return OK;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include "sls/sls_detector_funcs.h"
|
||||
#include "slsDetectorFunctionList.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD) || \
|
||||
defined(MYTHEN3D)
|
||||
@@ -10950,175 +10950,180 @@ int set_pattern_wait_interval(int file_des) {
|
||||
/**
|
||||
* Non destructive read from SPI register. Read n_bytes by shifting in dummy
|
||||
* data while keeping csn 0 after the operation. Shift the read out data back
|
||||
* in to restore the register.
|
||||
* in to restore the register.
|
||||
*/
|
||||
|
||||
int spi_read(int file_des){
|
||||
int spi_read(int file_des) {
|
||||
#if !defined(XILINX_CHIPTESTBOARDD)
|
||||
functionNotImplemented();
|
||||
return sendError(file_des);
|
||||
#endif
|
||||
|
||||
int chip_id = 0;
|
||||
if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0){
|
||||
if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(chip_id < 0 || chip_id > 15){
|
||||
if (chip_id < 0 || chip_id > 15) {
|
||||
sprintf(mess, "Invalid chip_id %d. Must be 0-15\n", chip_id);
|
||||
return sendError(file_des);
|
||||
}
|
||||
|
||||
int register_id = 0;
|
||||
if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0){
|
||||
if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(register_id < 0 || register_id > 15){
|
||||
if (register_id < 0 || register_id > 15) {
|
||||
sprintf(mess, "Invalid register_id %d. Must be 0-15\n", register_id);
|
||||
return sendError(file_des);
|
||||
}
|
||||
|
||||
int n_bytes = 0;
|
||||
if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0){
|
||||
if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(n_bytes < 1 ){
|
||||
sprintf(mess, "Invalid n_bytes %d. Must ask for a read of at least 1 byte\n", n_bytes);
|
||||
if (n_bytes < 1) {
|
||||
sprintf(mess,
|
||||
"Invalid n_bytes %d. Must ask for a read of at least 1 byte\n",
|
||||
n_bytes);
|
||||
return sendError(file_des);
|
||||
}
|
||||
|
||||
LOG(logINFO, ("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
|
||||
chip_id, register_id, n_bytes));
|
||||
|
||||
LOG(logINFO,
|
||||
("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
|
||||
chip_id, register_id, n_bytes));
|
||||
|
||||
#ifdef VIRTUAL
|
||||
// For the virtual detector we create a fake register to read from
|
||||
// and fill it with 0,2,4,6,... This way we can check that copying
|
||||
// of the data works as expected
|
||||
uint8_t *fake_register = malloc(n_bytes);
|
||||
if(fake_register == NULL){
|
||||
if (fake_register == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for fake register\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for (int i = 0; i < n_bytes; i++) {
|
||||
fake_register[i] = (uint8_t)( (i*2) % 256 );
|
||||
fake_register[i] = (uint8_t)((i * 2) % 256);
|
||||
}
|
||||
#else
|
||||
int spifd = open("/dev/spidev2.0", O_RDWR);
|
||||
LOG(logINFO, ("SPI Read: opened spidev2.0 with fd=%d\n", spifd));
|
||||
if(spifd < 0){
|
||||
if (spifd < 0) {
|
||||
sprintf(mess, "Could not open /dev/spidev2.0\n");
|
||||
return sendError(file_des);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allocate dummy data to shif in, we keep a copy of this
|
||||
// Allocate dummy data to shif in, we keep a copy of this
|
||||
// to double check that we access a register of the correct size
|
||||
uint8_t *dummy_data = malloc(n_bytes);
|
||||
if(dummy_data == NULL){
|
||||
if (dummy_data == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for dummy data\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for(int i=0; i<n_bytes; i++){
|
||||
for (int i = 0; i < n_bytes; i++) {
|
||||
dummy_data[i] = (uint8_t)(i % 256);
|
||||
}
|
||||
|
||||
// Allocate actual data buffer this holds the data we read out
|
||||
// Allocate actual data buffer this holds the data we read out
|
||||
// and that we need to write back to restore the register
|
||||
uint8_t *actual_data = malloc(n_bytes);
|
||||
if(actual_data == NULL){
|
||||
if (actual_data == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for actual data\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
memset(actual_data, 0, n_bytes);
|
||||
|
||||
|
||||
// Setup sending and receiving buffers and the spi_ioc_transfer struct.
|
||||
// We need one more byte before the actual data to send chip_id and register_id
|
||||
uint8_t* local_tx = malloc(n_bytes+1);
|
||||
if(local_tx == NULL){
|
||||
// We need one more byte before the actual data to send chip_id and
|
||||
// register_id
|
||||
uint8_t *local_tx = malloc(n_bytes + 1);
|
||||
if (local_tx == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for local_tx\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
uint8_t* local_rx = malloc(n_bytes+1);
|
||||
if(local_rx == NULL){
|
||||
uint8_t *local_rx = malloc(n_bytes + 1);
|
||||
if (local_rx == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for local_rx\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer send_cmd[1];
|
||||
memset(send_cmd, 0, sizeof(send_cmd));
|
||||
send_cmd[0].len = n_bytes+1;
|
||||
send_cmd[0].tx_buf = (unsigned long) local_tx;
|
||||
send_cmd[0].rx_buf = (unsigned long) local_rx;
|
||||
send_cmd[0].len = n_bytes + 1;
|
||||
send_cmd[0].tx_buf = (unsigned long)local_tx;
|
||||
send_cmd[0].rx_buf = (unsigned long)local_rx;
|
||||
|
||||
// 0 - Normal operation, 1 - CSN remains zero after operation
|
||||
// We use cs_change = 1 to not close the SPI transaction and
|
||||
// allow for shifting the read out data back in to restore the
|
||||
// regitster
|
||||
send_cmd[0].cs_change = 1;
|
||||
send_cmd[0].cs_change = 1;
|
||||
|
||||
// First byte of the message is 4 bits chip_id then 4 bits register_id
|
||||
local_tx[0] = ((chip_id & 0xF) << 4) | (register_id & 0xF);
|
||||
|
||||
// Then the data follows
|
||||
for (int i=0; i < n_bytes; i++)
|
||||
local_tx[i+1] = dummy_data[i];
|
||||
for (int i = 0; i < n_bytes; i++)
|
||||
local_tx[i + 1] = dummy_data[i];
|
||||
|
||||
#ifdef VIRTUAL
|
||||
// For the virtual detector we have to copy the data
|
||||
// For the virtual detector we have to copy the data
|
||||
|
||||
// First byte shuuld be 0x00
|
||||
local_rx[0] = 0;
|
||||
|
||||
// Then we copy the data from the fake register to the local_rx buffer
|
||||
// and the local_tx data to the fake register to emulate the shifting in and out of the data
|
||||
for (int i=0; i < n_bytes; i++){
|
||||
local_rx[i+1] = fake_register[i];
|
||||
fake_register[i] = local_tx[i+1];
|
||||
// and the local_tx data to the fake register to emulate the shifting in and
|
||||
// out of the data
|
||||
for (int i = 0; i < n_bytes; i++) {
|
||||
local_rx[i + 1] = fake_register[i];
|
||||
fake_register[i] = local_tx[i + 1];
|
||||
}
|
||||
|
||||
#else
|
||||
// For the real detector we do the transfer here
|
||||
if(ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd)<0){
|
||||
//cleanup since we return early
|
||||
if (ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd) < 0) {
|
||||
// cleanup since we return early
|
||||
close(spifd);
|
||||
free(local_tx);
|
||||
free(local_rx);
|
||||
free(dummy_data);
|
||||
free(actual_data);
|
||||
|
||||
//Send error message
|
||||
// Send error message
|
||||
sprintf(mess, "SPI write failed with %d:%s\n", errno, strerror(errno));
|
||||
return sendError(file_des);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Copy everything but the first received byte to the user. First byte should be 0x00 anyway
|
||||
for (int i=0; i < n_bytes; i++)
|
||||
actual_data[i] = local_rx[i+1];
|
||||
// Copy everything but the first received byte to the user. First byte
|
||||
// should be 0x00 anyway
|
||||
for (int i = 0; i < n_bytes; i++)
|
||||
actual_data[i] = local_rx[i + 1];
|
||||
|
||||
// Set up for the second transfer to restore the register
|
||||
send_cmd[0].cs_change = 0; // we want to end the transaction after this transfer
|
||||
send_cmd[0].cs_change =
|
||||
0; // we want to end the transaction after this transfer
|
||||
local_tx[0] = ((chip_id & 0xF) << 4) | (register_id & 0xF);
|
||||
for (int i=0; i < n_bytes; i++)
|
||||
local_tx[i+1] = actual_data[i];
|
||||
for (int i = 0; i < n_bytes; i++)
|
||||
local_tx[i + 1] = actual_data[i];
|
||||
|
||||
#ifdef VIRTUAL
|
||||
// Copy the data from the fake register to the local_rx buffer
|
||||
for (int i=0; i < n_bytes; i++){
|
||||
local_rx[i+1] = fake_register[i];
|
||||
for (int i = 0; i < n_bytes; i++) {
|
||||
local_rx[i + 1] = fake_register[i];
|
||||
}
|
||||
free(fake_register); // we are done with the fake register
|
||||
#else
|
||||
if(ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd)<0){
|
||||
//cleanup since we return early
|
||||
if (ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd) < 0) {
|
||||
// cleanup since we return early
|
||||
close(spifd);
|
||||
free(local_tx);
|
||||
free(local_rx);
|
||||
free(dummy_data);
|
||||
free(actual_data);
|
||||
|
||||
//Send error message
|
||||
// Send error message
|
||||
sprintf(mess, "SPI write failed with %d:%s\n", errno, strerror(errno));
|
||||
return sendError(file_des);
|
||||
}
|
||||
@@ -11130,29 +11135,26 @@ int spi_read(int file_des){
|
||||
sendData(file_des, actual_data, n_bytes, OTHER);
|
||||
|
||||
free(local_tx);
|
||||
free(local_rx);
|
||||
free(local_rx);
|
||||
free(dummy_data);
|
||||
free(actual_data);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Write to SPI register.
|
||||
* Write to SPI register.
|
||||
*/
|
||||
int spi_write(int file_des){
|
||||
int spi_write(int file_des) {
|
||||
#if !defined(XILINX_CHIPTESTBOARDD)
|
||||
functionNotImplemented();
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
#endif
|
||||
|
||||
int chip_id = 0;
|
||||
if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0){
|
||||
if (receiveData(file_des, &chip_id, sizeof(chip_id), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(chip_id < 0 || chip_id > 15){
|
||||
if (chip_id < 0 || chip_id > 15) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Invalid chip_id %d. Must be 0-15\n", chip_id);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -11160,10 +11162,10 @@ int spi_write(int file_des){
|
||||
}
|
||||
|
||||
int register_id = 0;
|
||||
if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0){
|
||||
if (receiveData(file_des, ®ister_id, sizeof(register_id), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(register_id < 0 || register_id > 15){
|
||||
if (register_id < 0 || register_id > 15) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Invalid register_id %d. Must be 0-15\n", register_id);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -11171,64 +11173,67 @@ int spi_write(int file_des){
|
||||
}
|
||||
|
||||
int n_bytes = 0;
|
||||
if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0){
|
||||
if (receiveData(file_des, &n_bytes, sizeof(n_bytes), INT32) < 0) {
|
||||
return printSocketReadError();
|
||||
}
|
||||
if(n_bytes < 1 ){
|
||||
sprintf(mess, "Invalid n_bytes %d. Must ask for a write of at least 1 byte\n", n_bytes);
|
||||
if (n_bytes < 1) {
|
||||
sprintf(mess,
|
||||
"Invalid n_bytes %d. Must ask for a write of at least 1 byte\n",
|
||||
n_bytes);
|
||||
return sendError(file_des);
|
||||
}
|
||||
|
||||
LOG(logINFO, ("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
|
||||
chip_id, register_id, n_bytes));
|
||||
|
||||
LOG(logINFO,
|
||||
("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
|
||||
chip_id, register_id, n_bytes));
|
||||
|
||||
uint8_t *data = malloc(n_bytes);
|
||||
if(data == NULL){
|
||||
if (data == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for SPI write data\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
memset(data, 0, n_bytes);
|
||||
if (receiveData(file_des, data, n_bytes, OTHER) < 0){
|
||||
if (receiveData(file_des, data, n_bytes, OTHER) < 0) {
|
||||
free(data);
|
||||
return printSocketReadError();
|
||||
}
|
||||
|
||||
uint8_t* local_tx = malloc(n_bytes+1);
|
||||
if(local_tx == NULL){
|
||||
uint8_t *local_tx = malloc(n_bytes + 1);
|
||||
if (local_tx == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for local_tx\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
uint8_t* local_rx = malloc(n_bytes+1);
|
||||
if(local_rx == NULL){
|
||||
uint8_t *local_rx = malloc(n_bytes + 1);
|
||||
if (local_rx == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for local_rx\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct spi_ioc_transfer send_cmd[1];
|
||||
memset(send_cmd, 0, sizeof(send_cmd));
|
||||
send_cmd[0].len = n_bytes+1;
|
||||
send_cmd[0].tx_buf = (unsigned long) local_tx;
|
||||
send_cmd[0].rx_buf = (unsigned long) local_rx;
|
||||
send_cmd[0].len = n_bytes + 1;
|
||||
send_cmd[0].tx_buf = (unsigned long)local_tx;
|
||||
send_cmd[0].rx_buf = (unsigned long)local_rx;
|
||||
|
||||
// 0 - Normal operation, 1 - CSn remains zero after operation
|
||||
send_cmd[0].cs_change = 0;
|
||||
send_cmd[0].cs_change = 0;
|
||||
local_tx[0] = ((chip_id & 0xF) << 4) | (register_id & 0xF);
|
||||
for (int i=0; i < n_bytes; i++)
|
||||
local_tx[i+1] = data[i];
|
||||
for (int i = 0; i < n_bytes; i++)
|
||||
local_tx[i + 1] = data[i];
|
||||
|
||||
#ifdef VIRTUAL
|
||||
// For the virtual detector we have nothing to do
|
||||
// For the virtual detector we have nothing to do
|
||||
#else
|
||||
int spifd = open("/dev/spidev2.0", O_RDWR);
|
||||
LOG(logINFO, ("SPI Read: opened spidev2.0 with fd=%d\n", spifd));
|
||||
if(spifd < 0){
|
||||
if (spifd < 0) {
|
||||
free(data);
|
||||
free(local_tx);
|
||||
free(local_rx);
|
||||
sprintf(mess, "Could not open /dev/spidev2.0\n");
|
||||
return sendError(file_des);
|
||||
}
|
||||
if(ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd)<0){
|
||||
if (ioctl(spifd, SPI_IOC_MESSAGE(1), &send_cmd) < 0) {
|
||||
close(spifd);
|
||||
free(data);
|
||||
free(local_tx);
|
||||
|
||||
@@ -427,13 +427,6 @@ void setupDetector() {
|
||||
if (initError == FAIL)
|
||||
return;
|
||||
}
|
||||
for (int idac = NDAC_ONLY; idac < NDAC; ++idac) {
|
||||
if (idac == D_PWR_EMPTY)
|
||||
continue;
|
||||
int min = (idac == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
// will not enable power at startup (dacValues = -1)
|
||||
setPower(idac, min);
|
||||
}
|
||||
|
||||
resetFlow();
|
||||
cleanFifos();
|
||||
|
||||
@@ -2248,10 +2248,10 @@ class Detector {
|
||||
///@}
|
||||
|
||||
Result<std::vector<uint8_t>> readSpi(int chip_id, int register_id,
|
||||
int n_bytes, Positions pos = {}) const;
|
||||
int n_bytes, Positions pos = {}) const;
|
||||
|
||||
void writeSpi(int chip_id, int register_id,
|
||||
const std::vector<uint8_t> &data, Positions pos = {});
|
||||
const std::vector<uint8_t> &data, Positions pos = {});
|
||||
|
||||
private:
|
||||
std::vector<uint16_t> getValidPortNumbers(uint16_t start_port);
|
||||
|
||||
@@ -2962,11 +2962,8 @@ Result<std::vector<uint8_t>> Detector::readSpi(int chip_id, int register_id,
|
||||
}
|
||||
|
||||
void Detector::writeSpi(int chip_id, int register_id,
|
||||
const std::vector<uint8_t> &data, Positions pos){
|
||||
const std::vector<uint8_t> &data, Positions pos) {
|
||||
pimpl->Parallel(&Module::writeSpi, pos, chip_id, register_id, data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -4076,7 +4076,7 @@ void Module::simulatingActivityinDetector(const std::string &functionType,
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Module::readSpi(int chip_id, int register_id,
|
||||
int n_bytes) const{
|
||||
int n_bytes) const {
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SPI_READ);
|
||||
client.setFnum(F_SPI_READ);
|
||||
@@ -4084,7 +4084,7 @@ std::vector<uint8_t> Module::readSpi(int chip_id, int register_id,
|
||||
client.Send(register_id);
|
||||
client.Send(n_bytes);
|
||||
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
std::ostringstream os;
|
||||
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
|
||||
<< " returned error: " << client.readErrorMessage();
|
||||
@@ -4094,11 +4094,10 @@ std::vector<uint8_t> Module::readSpi(int chip_id, int register_id,
|
||||
std::vector<uint8_t> data(n_bytes);
|
||||
client.Receive(data);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
void Module::writeSpi(int chip_id, int register_id,
|
||||
const std::vector<uint8_t> &data){
|
||||
const std::vector<uint8_t> &data) {
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SPI_WRITE);
|
||||
client.setFnum(F_SPI_WRITE);
|
||||
|
||||
@@ -608,9 +608,10 @@ class Module : public virtual slsDetectorDefs {
|
||||
int64_t getActualTime() const;
|
||||
int64_t getMeasurementTime() const;
|
||||
std::vector<uint8_t> readSpi(int chip_id, int register_id,
|
||||
int n_bytes) const;
|
||||
int n_bytes) const;
|
||||
|
||||
void writeSpi(int chip_id, int register_id, const std::vector<uint8_t> &data);
|
||||
void writeSpi(int chip_id, int register_id,
|
||||
const std::vector<uint8_t> &data);
|
||||
|
||||
private:
|
||||
std::string getReceiverLongVersion() const;
|
||||
|
||||
@@ -200,7 +200,7 @@ def runProcess(name, cmd, fp, log_file_name = None, quiet_mode=False):
|
||||
Log(LogLevel.INFOBLUE, info_text, fp, True)
|
||||
Log(LogLevel.INFOBLUE, 'Cmd: ' + ' '.join(cmd), fp, True)
|
||||
|
||||
error_log = None
|
||||
captured_log = []
|
||||
|
||||
try:
|
||||
if log_file_name:
|
||||
@@ -212,8 +212,8 @@ def runProcess(name, cmd, fp, log_file_name = None, quiet_mode=False):
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("error: ", str(e))
|
||||
captured_log = e.stdout.splitlines()
|
||||
pass
|
||||
if not log_file_name and e.stdout:
|
||||
captured_log = e.stdout.splitlines()
|
||||
except Exception as e:
|
||||
print("something else failed")
|
||||
Log(LogLevel.ERROR, f'Failed to run {name}:{str(e)}', fp)
|
||||
|
||||
Reference in New Issue
Block a user