formatted

This commit is contained in:
2026-02-10 16:10:51 +01:00
parent 1c18803dc9
commit 1c44a66964
5 changed files with 104 additions and 99 deletions

View File

@@ -7,9 +7,9 @@
#include "sls/sls_detector_funcs.h" #include "sls/sls_detector_funcs.h"
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <errno.h>
#if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD) || \ #if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD) || \
defined(MYTHEN3D) defined(MYTHEN3D)
@@ -11140,14 +11140,16 @@ int spi_read(int file_des){
return printSocketReadError(); return printSocketReadError();
} }
if (n_bytes < 1) { if (n_bytes < 1) {
sprintf(mess, "Invalid n_bytes %d. Must ask for a read of at least 1 byte\n", n_bytes); sprintf(mess,
"Invalid n_bytes %d. Must ask for a read of at least 1 byte\n",
n_bytes);
return sendError(file_des); return sendError(file_des);
} }
LOG(logINFO, ("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", LOG(logINFO,
("SPI Read Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
chip_id, register_id, n_bytes)); chip_id, register_id, n_bytes));
#ifdef VIRTUAL #ifdef VIRTUAL
// For the virtual detector we create a fake register to read from // 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 // and fill it with 0,2,4,6,... This way we can check that copying
@@ -11189,9 +11191,9 @@ int spi_read(int file_des){
} }
memset(actual_data, 0, n_bytes); memset(actual_data, 0, n_bytes);
// Setup sending and receiving buffers and the spi_ioc_transfer struct. // 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 // We need one more byte before the actual data to send chip_id and
// register_id
uint8_t *local_tx = malloc(n_bytes + 1); uint8_t *local_tx = malloc(n_bytes + 1);
if (local_tx == NULL) { if (local_tx == NULL) {
LOG(logERROR, ("Could not allocate memory for local_tx\n")); LOG(logERROR, ("Could not allocate memory for local_tx\n"));
@@ -11229,7 +11231,8 @@ int spi_read(int file_des){
local_rx[0] = 0; local_rx[0] = 0;
// Then we copy the data from the fake register to the local_rx buffer // 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 // 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++) { for (int i = 0; i < n_bytes; i++) {
local_rx[i + 1] = fake_register[i]; local_rx[i + 1] = fake_register[i];
fake_register[i] = local_tx[i + 1]; fake_register[i] = local_tx[i + 1];
@@ -11251,12 +11254,14 @@ int spi_read(int file_des){
} }
#endif #endif
// Copy everything but the first received byte to the user. First byte should be 0x00 anyway // Copy everything but the first received byte to the user. First byte
// should be 0x00 anyway
for (int i = 0; i < n_bytes; i++) for (int i = 0; i < n_bytes; i++)
actual_data[i] = local_rx[i + 1]; actual_data[i] = local_rx[i + 1];
// Set up for the second transfer to restore the register // 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); local_tx[0] = ((chip_id & 0xF) << 4) | (register_id & 0xF);
for (int i = 0; i < n_bytes; i++) for (int i = 0; i < n_bytes; i++)
local_tx[i + 1] = actual_data[i]; local_tx[i + 1] = actual_data[i];
@@ -11292,11 +11297,8 @@ int spi_read(int file_des){
free(dummy_data); free(dummy_data);
free(actual_data); free(actual_data);
return ret; return ret;
} }
/** /**
* Write to SPI register. * Write to SPI register.
*/ */
@@ -11333,11 +11335,14 @@ int spi_write(int file_des){
return printSocketReadError(); return printSocketReadError();
} }
if (n_bytes < 1) { if (n_bytes < 1) {
sprintf(mess, "Invalid n_bytes %d. Must ask for a write of at least 1 byte\n", n_bytes); sprintf(mess,
"Invalid n_bytes %d. Must ask for a write of at least 1 byte\n",
n_bytes);
return sendError(file_des); return sendError(file_des);
} }
LOG(logINFO, ("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n", LOG(logINFO,
("SPI Write Requested: chip_id=%d, register_id=%d, n_bytes=%d\n",
chip_id, register_id, n_bytes)); chip_id, register_id, n_bytes));
uint8_t *data = malloc(n_bytes); uint8_t *data = malloc(n_bytes);

View File

@@ -2251,7 +2251,8 @@ class Detector {
int n_bytes, Positions pos = {}) const; int n_bytes, Positions pos = {}) const;
Result<std::vector<uint8_t>> writeSpi(int chip_id, int register_id, Result<std::vector<uint8_t>> writeSpi(int chip_id, int register_id,
const std::vector<uint8_t> &data, Positions pos = {}); const std::vector<uint8_t> &data,
Positions pos = {});
private: private:
std::vector<uint16_t> getValidPortNumbers(uint16_t start_port); std::vector<uint16_t> getValidPortNumbers(uint16_t start_port);

View File

@@ -2961,12 +2961,10 @@ Result<std::vector<uint8_t>> Detector::readSpi(int chip_id, int register_id,
n_bytes); n_bytes);
} }
Result<std::vector<uint8_t>> Detector::writeSpi(int chip_id, int register_id, Result<std::vector<uint8_t>>
Detector::writeSpi(int chip_id, int register_id,
const std::vector<uint8_t> &data, Positions pos) { const std::vector<uint8_t> &data, Positions pos) {
return pimpl->Parallel(&Module::writeSpi, pos, chip_id, register_id, data); return pimpl->Parallel(&Module::writeSpi, pos, chip_id, register_id, data);
} }
} // namespace sls } // namespace sls

View File

@@ -4094,7 +4094,6 @@ std::vector<uint8_t> Module::readSpi(int chip_id, int register_id,
std::vector<uint8_t> data(n_bytes); std::vector<uint8_t> data(n_bytes);
client.Receive(data); client.Receive(data);
return data; return data;
} }
std::vector<uint8_t> Module::writeSpi(int chip_id, int register_id, std::vector<uint8_t> Module::writeSpi(int chip_id, int register_id,
@@ -4114,7 +4113,8 @@ std::vector<uint8_t> Module::writeSpi(int chip_id, int register_id,
throw DetectorError(os.str()); throw DetectorError(os.str());
} }
// Read the output from the SPI write. This contains the data before the write. // Read the output from the SPI write. This contains the data before the
// write.
std::vector<uint8_t> ret(data.size()); std::vector<uint8_t> ret(data.size());
client.Receive(ret); client.Receive(ret);
return ret; return ret;

View File

@@ -610,7 +610,8 @@ class Module : public virtual slsDetectorDefs {
std::vector<uint8_t> readSpi(int chip_id, int register_id, std::vector<uint8_t> readSpi(int chip_id, int register_id,
int n_bytes) const; int n_bytes) const;
std::vector<uint8_t> writeSpi(int chip_id, int register_id, const std::vector<uint8_t> &data); std::vector<uint8_t> writeSpi(int chip_id, int register_id,
const std::vector<uint8_t> &data);
private: private:
std::string getReceiverLongVersion() const; std::string getReceiverLongVersion() const;