mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-14 06:38:41 +01:00
formatted
This commit is contained in:
@@ -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)
|
||||
@@ -11140,14 +11140,16 @@ int spi_read(int file_des){
|
||||
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);
|
||||
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",
|
||||
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
|
||||
@@ -11189,9 +11191,9 @@ int spi_read(int file_des){
|
||||
}
|
||||
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
|
||||
// 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"));
|
||||
@@ -11229,7 +11231,8 @@ int spi_read(int file_des){
|
||||
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
|
||||
// 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];
|
||||
@@ -11251,12 +11254,14 @@ int spi_read(int file_des){
|
||||
}
|
||||
#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++)
|
||||
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];
|
||||
@@ -11292,11 +11297,8 @@ int spi_read(int file_des){
|
||||
free(dummy_data);
|
||||
free(actual_data);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Write to SPI register.
|
||||
*/
|
||||
@@ -11333,11 +11335,14 @@ int spi_write(int file_des){
|
||||
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);
|
||||
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",
|
||||
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);
|
||||
|
||||
@@ -2251,7 +2251,8 @@ class Detector {
|
||||
int n_bytes, Positions pos = {}) const;
|
||||
|
||||
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:
|
||||
std::vector<uint16_t> getValidPortNumbers(uint16_t start_port);
|
||||
|
||||
@@ -2961,12 +2961,10 @@ Result<std::vector<uint8_t>> Detector::readSpi(int chip_id, int register_id,
|
||||
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) {
|
||||
return pimpl->Parallel(&Module::writeSpi, pos, chip_id, register_id, data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -4094,7 +4094,6 @@ std::vector<uint8_t> Module::readSpi(int chip_id, int register_id,
|
||||
std::vector<uint8_t> data(n_bytes);
|
||||
client.Receive(data);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// 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());
|
||||
client.Receive(ret);
|
||||
return ret;
|
||||
|
||||
@@ -610,7 +610,8 @@ class Module : public virtual slsDetectorDefs {
|
||||
std::vector<uint8_t> readSpi(int chip_id, int register_id,
|
||||
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:
|
||||
std::string getReceiverLongVersion() const;
|
||||
|
||||
Reference in New Issue
Block a user