gotthard2: veto reference, better code for byte aligment in server

This commit is contained in:
2019-11-15 11:58:23 +01:00
parent 5518531620
commit a62d6a2fb8
4 changed files with 31 additions and 29 deletions

View File

@ -1137,40 +1137,41 @@ int setVetoPhoton(int chipIndex, int gainIndex, int* values) {
FILE_LOG(logDEBUG1, ("Value %d: 0x%x\n", i, values[i])); FILE_LOG(logDEBUG1, ("Value %d: 0x%x\n", i, values[i]));
} }
} }
// create command
const int lenAduBits = ASIC_GAIN_MAX_BITS + ADU_MAX_BITS; const int lenDataBitsPerchannel = ASIC_GAIN_MAX_BITS + ADU_MAX_BITS; // 14
const int lenBits = lenAduBits * NCHAN; const int lenBits = lenDataBitsPerchannel * NCHAN; // 1792
const int len = lenBits / 8; const int padding = 4; // due to address (4) to make it byte aligned
char buffer[len]; const int lenTotalBits = padding + lenBits + ASIC_ADDR_MAX_BITS; // 1800
memset(buffer, 0, len); const int len = lenTotalBits / 8; // 225
int iBit = 4; // 4 due to padding
// assign each bit into 4 + 1792 into byte array
uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes
int ich = 0; int ich = 0;
for (ich = 0; ich < NCHAN; ++ich) { for (ich = 0; ich < NCHAN; ++ich) {
// copy 14 bits for each channel // loop through all bits in a value
int totalToCopy = lenAduBits; int iBit = 0;
while (totalToCopy > 0) { for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) {
int byteIndex = iBit / 8; commandBytes[offset++] = ((values[ich] >> (lenDataBitsPerchannel - 1 - iBit)) & 0x1);
int bitIndex = iBit % 8; }
// how much to copy in a byte }
int toCopy = 8 - bitIndex;
if (toCopy > totalToCopy) { // create command for 4 padding + 1792 bits + 4 bits address = 1800 bits = 225 bytes
toCopy = totalToCopy; char buffer[len];
} memset(buffer, 0, len);
int copyMask = (1 << toCopy) - 1; offset = 0;
// value pushed out by whats left and masked // loop through buffer elements
int val = (values[ich] >> (totalToCopy - toCopy)) & copyMask; for (ich = 0; ich < len; ++ich) {
if (toCopy + bitIndex != 8) { // loop through each bit in buffer element
val = val << (8 - bitIndex - toCopy); int iBit = 0;
} for (iBit = 0; iBit < 8; ++iBit) {
buffer[byteIndex] |= val; buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
// incrememnt indices
iBit += toCopy;
totalToCopy -= toCopy;
} }
} }
// address at the end // address at the end
buffer[16] |= (ASIC_VETO_REF_ADDR); buffer[len -1] |= (ASIC_VETO_REF_ADDR);
if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) { if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) {
return FAIL; return FAIL;

View File

@ -82,6 +82,7 @@ enum PLLINDEX {READOUT_PLL, SYSTEM_PLL};
/** Chip Definitions */ /** Chip Definitions */
#define ASIC_ADDR_MAX_BITS (4)
#define ASIC_CURRENT_INJECT_ADDR (0x9) #define ASIC_CURRENT_INJECT_ADDR (0x9)
#define ASIC_VETO_REF_ADDR (0xA) #define ASIC_VETO_REF_ADDR (0xA)
#define ASIC_GAIN_MAX_BITS (2) #define ASIC_GAIN_MAX_BITS (2)

View File

@ -9,4 +9,4 @@
#define APIJUNGFRAU 0x191111 #define APIJUNGFRAU 0x191111
#define APIEIGER 0x191111 #define APIEIGER 0x191111
#define APIMYTHEN3 0x191111 #define APIMYTHEN3 0x191111
#define APIGOTTHARD2 0x191114 #define APIGOTTHARD2 0x191115