mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
nios, for variable delcaration in loop
This commit is contained in:
parent
9b21f44d94
commit
2f11dbc2c9
@ -217,9 +217,8 @@ int testBus() {
|
|||||||
int ret = OK;
|
int ret = OK;
|
||||||
u_int32_t addr = DTA_OFFSET_REG;
|
u_int32_t addr = DTA_OFFSET_REG;
|
||||||
u_int32_t times = 1000 * 1000;
|
u_int32_t times = 1000 * 1000;
|
||||||
u_int32_t i = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < times; ++i) {
|
for (u_int32_t i = 0; i < times; ++i) {
|
||||||
bus_w(addr, i * 100);
|
bus_w(addr, i * 100);
|
||||||
if (i * 100 != bus_r(addr)) {
|
if (i * 100 != bus_r(addr)) {
|
||||||
LOG(logERROR,
|
LOG(logERROR,
|
||||||
@ -375,28 +374,25 @@ void setupDetector() {
|
|||||||
delayReg = 0;
|
delayReg = 0;
|
||||||
numBurstsReg = 1;
|
numBurstsReg = 1;
|
||||||
burstPeriodReg = 0;
|
burstPeriodReg = 0;
|
||||||
{
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
int i, j;
|
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
clkPhase[i] = 0;
|
clkPhase[i] = 0;
|
||||||
}
|
}
|
||||||
for (i = 0; i < NDAC; ++i) {
|
for (int i = 0; i < NDAC; ++i) {
|
||||||
dacValues[i] = 0;
|
dacValues[i] = 0;
|
||||||
}
|
}
|
||||||
for (i = 0; i < ONCHIP_NDAC; ++i) {
|
for (int i = 0; i < ONCHIP_NDAC; ++i) {
|
||||||
for (j = 0; j < NCHIP; ++j) {
|
for (int j = 0; j < NCHIP; ++j) {
|
||||||
onChipdacValues[i][j] = -1;
|
onChipdacValues[i][j] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < NCHIP; ++i) {
|
for (int i = 0; i < NCHIP; ++i) {
|
||||||
for (j = 0; j < NCHAN; ++j) {
|
for (int j = 0; j < NCHAN; ++j) {
|
||||||
vetoReference[i][j] = 0;
|
vetoReference[i][j] = 0;
|
||||||
}
|
}
|
||||||
for (j = 0; j < NADC; ++j) {
|
for (int j = 0; j < NADC; ++j) {
|
||||||
adcConfiguration[i][j] = 0;
|
adcConfiguration[i][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
if (isControlServer) {
|
if (isControlServer) {
|
||||||
@ -647,9 +643,8 @@ int readConfigFile() {
|
|||||||
adcmax = iadc + 1;
|
adcmax = iadc + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i, j;
|
for (int i = chipmin; i < chipmax; ++i) {
|
||||||
for (i = chipmin; i < chipmax; ++i) {
|
for (int j = adcmin; j < adcmax; ++j) {
|
||||||
for (j = adcmin; j < adcmax; ++j) {
|
|
||||||
adcConfiguration[i][j] = (uint8_t)value;
|
adcConfiguration[i][j] = (uint8_t)value;
|
||||||
++nadcRead;
|
++nadcRead;
|
||||||
}
|
}
|
||||||
@ -776,13 +771,10 @@ int readConfigFile() {
|
|||||||
nadcRead, NADC * NCHIP);
|
nadcRead, NADC * NCHIP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
for (int i = 0; i < NCHIP; ++i) {
|
||||||
int i = 0, j = 0;
|
for (int j = 0; j < NADC; ++j) {
|
||||||
for (i = 0; i < NCHIP; ++i) {
|
LOG(logDEBUG2,
|
||||||
for (j = 0; j < NADC; ++j) {
|
("adc read %d %d: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
|
||||||
LOG(logDEBUG2, ("adc read %d %d: 0x%02hhx\n", i, j,
|
|
||||||
adcConfiguration[i][j]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1143,8 +1135,7 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val) {
|
|||||||
}
|
}
|
||||||
// all chips
|
// all chips
|
||||||
if (chipIndex == -1) {
|
if (chipIndex == -1) {
|
||||||
int ichip = 0;
|
for (int ichip = 0; ichip < NCHIP; ++ichip) {
|
||||||
for (ichip = 0; ichip < NCHIP; ++ichip) {
|
|
||||||
onChipdacValues[ind][ichip] = val;
|
onChipdacValues[ind][ichip] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1160,9 +1151,8 @@ int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex) {
|
|||||||
// all chips
|
// all chips
|
||||||
if (chipIndex == -1) {
|
if (chipIndex == -1) {
|
||||||
int retval = onChipdacValues[ind][0];
|
int retval = onChipdacValues[ind][0];
|
||||||
int ichip = 0;
|
|
||||||
// check if same value for remaining chips
|
// check if same value for remaining chips
|
||||||
for (ichip = 1; ichip < NCHIP; ++ichip) {
|
for (int ichip = 1; ichip < NCHIP; ++ichip) {
|
||||||
if (onChipdacValues[ind][ichip] != retval) {
|
if (onChipdacValues[ind][ichip] != retval) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1641,8 +1631,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
// Remembering old phases in degrees
|
// Remembering old phases in degrees
|
||||||
int oldPhases[NUM_CLOCKS];
|
int oldPhases[NUM_CLOCKS];
|
||||||
{
|
{
|
||||||
int i = 0;
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
oldPhases[i] = getPhase(i, 1);
|
oldPhases[i] = getPhase(i, 1);
|
||||||
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
|
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
|
||||||
clock_names[ind], ind, oldPhases[i]));
|
clock_names[ind], ind, oldPhases[i]));
|
||||||
@ -1673,9 +1662,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the phase in degrees (reset by pll)
|
// set the phase in degrees (reset by pll)
|
||||||
{
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
int currPhaseDeg = getPhase(i, 1);
|
int currPhaseDeg = getPhase(i, 1);
|
||||||
if (oldPhases[i] != currPhaseDeg) {
|
if (oldPhases[i] != currPhaseDeg) {
|
||||||
LOG(logINFO,
|
LOG(logINFO,
|
||||||
@ -1684,7 +1671,6 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
setPhase(i, oldPhases[i], 1);
|
setPhase(i, oldPhases[i], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1711,8 +1697,8 @@ int setInjectChannel(int offset, int increment) {
|
|||||||
char buffer[17];
|
char buffer[17];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
int startCh = 4; // 4 due to padding
|
int startCh = 4; // 4 due to padding
|
||||||
int ich = 0;
|
for (int ich = startCh + offset; ich < startCh + NCHAN;
|
||||||
for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) {
|
ich = ich + increment) {
|
||||||
int byteIndex = ich / 8;
|
int byteIndex = ich / 8;
|
||||||
int bitIndex = ich % 8;
|
int bitIndex = ich % 8;
|
||||||
buffer[byteIndex] |= (1 << (8 - 1 - bitIndex));
|
buffer[byteIndex] |= (1 << (8 - 1 - bitIndex));
|
||||||
@ -1741,8 +1727,7 @@ int setVetoReference(int gainIndex, int value) {
|
|||||||
gainIndex, value));
|
gainIndex, value));
|
||||||
int vals[NCHAN];
|
int vals[NCHAN];
|
||||||
memset(vals, 0, sizeof(vals));
|
memset(vals, 0, sizeof(vals));
|
||||||
int ich = 0;
|
for (int ich = 0; ich < NCHAN; ++ich) {
|
||||||
for (ich = 0; ich < NCHAN; ++ich) {
|
|
||||||
vals[ich] = value;
|
vals[ich] = value;
|
||||||
}
|
}
|
||||||
return setVetoPhoton(-1, gainIndex, vals);
|
return setVetoPhoton(-1, gainIndex, vals);
|
||||||
@ -1770,8 +1755,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logDEBUG2, ("Adding gain bits\n"));
|
LOG(logDEBUG2, ("Adding gain bits\n"));
|
||||||
int i = 0;
|
for (int i = 0; i < NCHAN; ++i) {
|
||||||
for (i = 0; i < NCHAN; ++i) {
|
|
||||||
values[i] |= gainValue;
|
values[i] |= gainValue;
|
||||||
LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i]));
|
LOG(logDEBUG2, ("Value %d: 0x%x\n", i, values[i]));
|
||||||
}
|
}
|
||||||
@ -1787,8 +1771,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
uint8_t commandBytes[lenTotalBits];
|
uint8_t commandBytes[lenTotalBits];
|
||||||
memset(commandBytes, 0, sizeof(commandBytes));
|
memset(commandBytes, 0, sizeof(commandBytes));
|
||||||
int offset = padding; // bit offset for commandbytes
|
int offset = padding; // bit offset for commandbytes
|
||||||
int ich = 0;
|
for (int ich = 0; ich < NCHAN; ++ich) {
|
||||||
for (ich = 0; ich < NCHAN; ++ich) {
|
|
||||||
// loop through all bits in a value
|
// loop through all bits in a value
|
||||||
int iBit = 0;
|
int iBit = 0;
|
||||||
for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) {
|
for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) {
|
||||||
@ -1803,10 +1786,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
// loop through buffer elements
|
// loop through buffer elements
|
||||||
for (ich = 0; ich < len; ++ich) {
|
for (int ich = 0; ich < len; ++ich) {
|
||||||
// loop through each bit in buffer element
|
// loop through each bit in buffer element
|
||||||
int iBit = 0;
|
for (int iBit = 0; iBit < 8; ++iBit) {
|
||||||
for (iBit = 0; iBit < 8; ++iBit) {
|
|
||||||
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1820,10 +1802,8 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
|
|
||||||
// all chips
|
// all chips
|
||||||
if (chipIndex == -1) {
|
if (chipIndex == -1) {
|
||||||
int ichip = 0;
|
for (int ichan = 0; ichan < NCHAN; ++ichan) {
|
||||||
int ichan = 0;
|
for (int ichip = 0; ichip < NCHIP; ++ichip) {
|
||||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
|
||||||
for (ichip = 0; ichip < NCHIP; ++ichip) {
|
|
||||||
vetoReference[ichip][ichan] = values[ichan];
|
vetoReference[ichip][ichan] = values[ichan];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1831,8 +1811,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
|
|
||||||
// specific chip
|
// specific chip
|
||||||
else {
|
else {
|
||||||
int ichan = 0;
|
for (int ichan = 0; ichan < NCHAN; ++ichan) {
|
||||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
|
||||||
vetoReference[chipIndex][chipIndex] = values[ichan];
|
vetoReference[chipIndex][chipIndex] = values[ichan];
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -1842,10 +1821,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
|
|||||||
|
|
||||||
int getVetoPhoton(int chipIndex, int *retvals) {
|
int getVetoPhoton(int chipIndex, int *retvals) {
|
||||||
if (chipIndex == -1) {
|
if (chipIndex == -1) {
|
||||||
int i = 0, j = 0;
|
for (int i = 0; i < NCHAN; ++i) {
|
||||||
for (i = 0; i < NCHAN; ++i) {
|
|
||||||
int val = vetoReference[0][i];
|
int val = vetoReference[0][i];
|
||||||
for (j = 1; j < NCHIP; ++j) {
|
for (int j = 1; j < NCHIP; ++j) {
|
||||||
if (vetoReference[j][i] != val) {
|
if (vetoReference[j][i] != val) {
|
||||||
LOG(logERROR,
|
LOG(logERROR,
|
||||||
("Get vet photon fail for chipIndex:%d. Different "
|
("Get vet photon fail for chipIndex:%d. Different "
|
||||||
@ -1876,15 +1854,12 @@ int configureSingleADCDriver(int chipIndex) {
|
|||||||
memcpy(values, adcConfiguration + ind * NADC, NADC);
|
memcpy(values, adcConfiguration + ind * NADC, NADC);
|
||||||
|
|
||||||
// change adc values if continuous mode
|
// change adc values if continuous mode
|
||||||
{
|
for (int i = 0; i < NADC; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < NADC; ++i) {
|
|
||||||
if (burstMode == BURST_OFF) {
|
if (burstMode == BURST_OFF) {
|
||||||
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
|
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
|
||||||
}
|
}
|
||||||
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
|
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
|
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
|
||||||
const int lenBits = lenDataBitsPerADC * NADC; // 224
|
const int lenBits = lenDataBitsPerADC * NADC; // 224
|
||||||
@ -1896,11 +1871,9 @@ int configureSingleADCDriver(int chipIndex) {
|
|||||||
uint8_t commandBytes[lenTotalBits];
|
uint8_t commandBytes[lenTotalBits];
|
||||||
memset(commandBytes, 0, sizeof(commandBytes));
|
memset(commandBytes, 0, sizeof(commandBytes));
|
||||||
int offset = padding; // bit offset for commandbytes
|
int offset = padding; // bit offset for commandbytes
|
||||||
int ich = 0;
|
for (int ich = 0; ich < NADC; ++ich) {
|
||||||
for (ich = 0; ich < NADC; ++ich) {
|
|
||||||
// loop through all bits in a value
|
// loop through all bits in a value
|
||||||
int iBit = 0;
|
for (int iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
|
||||||
for (iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
|
|
||||||
commandBytes[offset++] =
|
commandBytes[offset++] =
|
||||||
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
|
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
|
||||||
}
|
}
|
||||||
@ -1912,10 +1885,9 @@ int configureSingleADCDriver(int chipIndex) {
|
|||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
// loop through buffer elements
|
// loop through buffer elements
|
||||||
for (ich = 0; ich < len; ++ich) {
|
for (int ich = 0; ich < len; ++ich) {
|
||||||
// loop through each bit in buffer element
|
// loop through each bit in buffer element
|
||||||
int iBit = 0;
|
for (int iBit = 0; iBit < 8; ++iBit) {
|
||||||
for (iBit = 0; iBit < 8; ++iBit) {
|
|
||||||
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1934,23 +1906,19 @@ int configureADC() {
|
|||||||
LOG(logINFO, ("Configuring ADC \n"));
|
LOG(logINFO, ("Configuring ADC \n"));
|
||||||
|
|
||||||
int equal = 1;
|
int equal = 1;
|
||||||
{
|
for (int i = 0; i < NADC; ++i) {
|
||||||
int i = 0, j = 0;
|
|
||||||
for (i = 0; i < NADC; ++i) {
|
|
||||||
int val = adcConfiguration[0][i];
|
int val = adcConfiguration[0][i];
|
||||||
for (j = 1; j < NCHIP; ++j) {
|
for (int j = 1; j < NCHIP; ++j) {
|
||||||
if (adcConfiguration[j][i] != val) {
|
if (adcConfiguration[j][i] != val) {
|
||||||
equal = 0;
|
equal = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (equal) {
|
if (equal) {
|
||||||
return configureSingleADCDriver(-1);
|
return configureSingleADCDriver(-1);
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
for (int i = 0; i < NCHIP; ++i) {
|
||||||
for (i = 0; i < NCHIP; ++i) {
|
|
||||||
if (configureSingleADCDriver(i) == FAIL) {
|
if (configureSingleADCDriver(i) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -2075,10 +2043,8 @@ int setBurstMode(enum burstMode burst) {
|
|||||||
uint8_t commandBytes[lenTotalBits];
|
uint8_t commandBytes[lenTotalBits];
|
||||||
memset(commandBytes, 0, sizeof(commandBytes));
|
memset(commandBytes, 0, sizeof(commandBytes));
|
||||||
int offset = padding; // bit offset for commandbytes
|
int offset = padding; // bit offset for commandbytes
|
||||||
int ich = 0;
|
|
||||||
// loop through all bits in a value
|
// loop through all bits in a value
|
||||||
int iBit = 0;
|
for (int iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
|
||||||
for (iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
|
|
||||||
commandBytes[offset++] =
|
commandBytes[offset++] =
|
||||||
((value >> (ASIC_GLOBAL_SETT_MAX_BITS - 1 - iBit)) & 0x1);
|
((value >> (ASIC_GLOBAL_SETT_MAX_BITS - 1 - iBit)) & 0x1);
|
||||||
}
|
}
|
||||||
@ -2089,10 +2055,9 @@ int setBurstMode(enum burstMode burst) {
|
|||||||
memset(buffer, 0, len);
|
memset(buffer, 0, len);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
// loop through buffer elements
|
// loop through buffer elements
|
||||||
for (ich = 0; ich < len; ++ich) {
|
for (int ich = 0; ich < len; ++ich) {
|
||||||
// loop through each bit in buffer element
|
// loop through each bit in buffer element
|
||||||
int iBit = 0;
|
for (int iBit = 0; iBit < 8; ++iBit) {
|
||||||
for (iBit = 0; iBit < 8; ++iBit) {
|
|
||||||
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2235,25 +2200,20 @@ void *start_timer(void *arg) {
|
|||||||
// Generate data
|
// Generate data
|
||||||
char imageData[imagesize];
|
char imageData[imagesize];
|
||||||
memset(imageData, 0, imagesize);
|
memset(imageData, 0, imagesize);
|
||||||
{
|
for (int i = 0; i < imagesize; i += sizeof(uint16_t)) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < imagesize; i += sizeof(uint16_t)) {
|
|
||||||
*((uint16_t *)(imageData + i)) = i;
|
*((uint16_t *)(imageData + i)) = i;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int repeatNr = 0;
|
|
||||||
int frameHeaderNr = 0;
|
int frameHeaderNr = 0;
|
||||||
// loop over number of repeats
|
// loop over number of repeats
|
||||||
for (repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
|
for (int repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
|
||||||
|
|
||||||
struct timespec rbegin, rend;
|
struct timespec rbegin, rend;
|
||||||
clock_gettime(CLOCK_REALTIME, &rbegin);
|
clock_gettime(CLOCK_REALTIME, &rbegin);
|
||||||
|
|
||||||
int frameNr = 0;
|
|
||||||
// loop over number of frames
|
// loop over number of frames
|
||||||
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
|
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
|
||||||
|
|
||||||
// update the virtual stop from stop server
|
// update the virtual stop from stop server
|
||||||
virtual_stop = ComVirtual_getStop();
|
virtual_stop = ComVirtual_getStop();
|
||||||
|
@ -208,9 +208,8 @@ int testBus() {
|
|||||||
int ret = OK;
|
int ret = OK;
|
||||||
u_int32_t addr = DTA_OFFSET_REG;
|
u_int32_t addr = DTA_OFFSET_REG;
|
||||||
u_int32_t times = 1000 * 1000;
|
u_int32_t times = 1000 * 1000;
|
||||||
u_int32_t i = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < times; ++i) {
|
for (u_int32_t i = 0; i < times; ++i) {
|
||||||
bus_w(addr, i * 100);
|
bus_w(addr, i * 100);
|
||||||
if (i * 100 != bus_r(addr)) {
|
if (i * 100 != bus_r(addr)) {
|
||||||
LOG(logERROR,
|
LOG(logERROR,
|
||||||
@ -365,14 +364,12 @@ void allocateDetectorStructureMemory() {
|
|||||||
// thisSettings = UNINITIALIZED;
|
// thisSettings = UNINITIALIZED;
|
||||||
|
|
||||||
// initialize dacs
|
// initialize dacs
|
||||||
int idac = 0;
|
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
|
||||||
for (idac = 0; idac < (detectorModules)->ndac; ++idac) {
|
|
||||||
detectorDacs[idac] = 0;
|
detectorDacs[idac] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if trimval requested, should return -1 to acknowledge unknown
|
// if trimval requested, should return -1 to acknowledge unknown
|
||||||
int ichan = 0;
|
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
|
||||||
for (ichan = 0; ichan < (detectorModules->nchan); ichan++) {
|
|
||||||
*((detectorModules->chanregs) + ichan) = -1;
|
*((detectorModules->chanregs) + ichan) = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -390,12 +387,9 @@ void setupDetector() {
|
|||||||
|
|
||||||
highvoltage = 0;
|
highvoltage = 0;
|
||||||
trimmingPrint = logINFO;
|
trimmingPrint = logINFO;
|
||||||
{
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
int i;
|
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
clkPhase[i] = 0;
|
clkPhase[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
if (isControlServer) {
|
if (isControlServer) {
|
||||||
@ -441,9 +435,8 @@ int setDefaultDacs() {
|
|||||||
int ret = OK;
|
int ret = OK;
|
||||||
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
|
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
|
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
|
||||||
for (i = 0; i < NDAC; ++i) {
|
for (int i = 0; i < NDAC; ++i) {
|
||||||
setDAC((enum DACINDEX)i, defaultvals[i], 0);
|
setDAC((enum DACINDEX)i, defaultvals[i], 0);
|
||||||
if (detectorDacs[i] != defaultvals[i]) {
|
if (detectorDacs[i] != defaultvals[i]) {
|
||||||
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i,
|
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i,
|
||||||
@ -551,20 +544,16 @@ int setModule(sls_detector_module myMod, char *mess) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// dacs
|
// dacs
|
||||||
{
|
for (int i = 0; i < NDAC; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < NDAC; ++i) {
|
|
||||||
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
|
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
|
||||||
if (myMod.dacs[i] != detectorDacs[i]) {
|
if (myMod.dacs[i] != detectorDacs[i]) {
|
||||||
sprintf(mess, "Could not set module. Could not set dac %d\n",
|
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
|
||||||
i);
|
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
// setSettings(UNDEFINED);
|
// setSettings(UNDEFINED);
|
||||||
// LOG(logERROR, ("Settings has been changed to undefined\n"));
|
// LOG(logERROR, ("Settings has been changed to undefined\n"));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// trimbits
|
// trimbits
|
||||||
if (myMod.nchan == 0) {
|
if (myMod.nchan == 0) {
|
||||||
@ -602,8 +591,7 @@ int setTrimbits(int *trimbits) {
|
|||||||
LOG(logINFOBLUE, ("Setting trimbits\n"));
|
LOG(logINFOBLUE, ("Setting trimbits\n"));
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
int ichan = 0;
|
for (int ichan = 0; ichan < NCHAN; ++ichan) {
|
||||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
|
||||||
if (trimbits[ichan] < 0 || trimbits[ichan] > 63) {
|
if (trimbits[ichan] < 0 || trimbits[ichan] > 63) {
|
||||||
LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid\n",
|
LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid\n",
|
||||||
trimbits[ichan], ichan));
|
trimbits[ichan], ichan));
|
||||||
@ -615,8 +603,7 @@ int setTrimbits(int *trimbits) {
|
|||||||
|
|
||||||
uint64_t patword = 0;
|
uint64_t patword = 0;
|
||||||
int iaddr = 0;
|
int iaddr = 0;
|
||||||
int ichip = 0;
|
for (int ichip = 0; ichip < NCHIP; ichip++) {
|
||||||
for (ichip = 0; ichip < NCHIP; ichip++) {
|
|
||||||
LOG(logINFOBLUE, (" Chip %d\n", ichip));
|
LOG(logINFOBLUE, (" Chip %d\n", ichip));
|
||||||
iaddr = 0;
|
iaddr = 0;
|
||||||
patword = 0;
|
patword = 0;
|
||||||
@ -733,8 +720,7 @@ int setTrimbits(int *trimbits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy trimbits locally
|
// copy trimbits locally
|
||||||
ichan = 0;
|
for (int ichan = 0; ichan < NCHAN; ++ichan) {
|
||||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
|
||||||
detectorChans[ichan] = trimbits[ichan];
|
detectorChans[ichan] = trimbits[ichan];
|
||||||
}
|
}
|
||||||
trimmingPrint = logINFO;
|
trimmingPrint = logINFO;
|
||||||
@ -743,8 +729,7 @@ int setTrimbits(int *trimbits) {
|
|||||||
|
|
||||||
int setAllTrimbits(int val) {
|
int setAllTrimbits(int val) {
|
||||||
int *trimbits = malloc(sizeof(int) * NCHAN);
|
int *trimbits = malloc(sizeof(int) * NCHAN);
|
||||||
int ichan = 0;
|
for (int ichan = 0; ichan < NCHAN; ++ichan) {
|
||||||
for (ichan = 0; ichan < NCHAN; ++ichan) {
|
|
||||||
trimbits[ichan] = val;
|
trimbits[ichan] = val;
|
||||||
}
|
}
|
||||||
if (setTrimbits(trimbits) == FAIL) {
|
if (setTrimbits(trimbits) == FAIL) {
|
||||||
@ -761,10 +746,9 @@ int setAllTrimbits(int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getAllTrimbits() {
|
int getAllTrimbits() {
|
||||||
int ichan = 0;
|
|
||||||
int value = detectorChans[0];
|
int value = detectorChans[0];
|
||||||
if (detectorModules) {
|
if (detectorModules) {
|
||||||
for (ichan = 0; ichan < NCHAN; ichan++) {
|
for (int ichan = 0; ichan < NCHAN; ichan++) {
|
||||||
if (detectorChans[ichan] != value) {
|
if (detectorChans[ichan] != value) {
|
||||||
value = -1;
|
value = -1;
|
||||||
break;
|
break;
|
||||||
@ -1644,14 +1628,11 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
|
|
||||||
// Remembering old phases in degrees
|
// Remembering old phases in degrees
|
||||||
int oldPhases[NUM_CLOCKS];
|
int oldPhases[NUM_CLOCKS];
|
||||||
{
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
oldPhases[i] = getPhase(i, 1);
|
oldPhases[i] = getPhase(i, 1);
|
||||||
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
|
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
|
||||||
clock_names[ind], ind, oldPhases[i]));
|
clock_names[ind], ind, oldPhases[i]));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate and set output frequency
|
// Calculate and set output frequency
|
||||||
int pllIndex = (int)(ind >= SYSTEM_C0 ? SYSTEM_PLL : READOUT_PLL);
|
int pllIndex = (int)(ind >= SYSTEM_C0 ? SYSTEM_PLL : READOUT_PLL);
|
||||||
@ -1672,9 +1653,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the phase in degrees (reset by pll)
|
// set the phase in degrees (reset by pll)
|
||||||
{
|
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < NUM_CLOCKS; ++i) {
|
|
||||||
int currPhaseDeg = getPhase(i, 1);
|
int currPhaseDeg = getPhase(i, 1);
|
||||||
if (oldPhases[i] != currPhaseDeg) {
|
if (oldPhases[i] != currPhaseDeg) {
|
||||||
LOG(logINFO,
|
LOG(logINFO,
|
||||||
@ -1683,7 +1662,6 @@ int setClockDivider(enum CLKINDEX ind, int val) {
|
|||||||
setPhase(i, oldPhases[i], 1);
|
setPhase(i, oldPhases[i], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1754,18 +1732,13 @@ void *start_timer(void *arg) {
|
|||||||
// Generate data
|
// Generate data
|
||||||
char imageData[imagesize];
|
char imageData[imagesize];
|
||||||
memset(imageData, 0, imagesize);
|
memset(imageData, 0, imagesize);
|
||||||
{
|
for (int i = 0; i < imagesize; i += sizeof(uint8_t)) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < imagesize; i += sizeof(uint8_t)) {
|
|
||||||
*((uint8_t *)(imageData + i)) = i;
|
*((uint8_t *)(imageData + i)) = i;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Send data
|
// Send data
|
||||||
{
|
|
||||||
int frameNr = 1;
|
|
||||||
// loop over number of frames
|
// loop over number of frames
|
||||||
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
|
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
|
||||||
|
|
||||||
// update the virtual stop from stop server
|
// update the virtual stop from stop server
|
||||||
virtual_stop = ComVirtual_getStop();
|
virtual_stop = ComVirtual_getStop();
|
||||||
@ -1781,15 +1754,12 @@ void *start_timer(void *arg) {
|
|||||||
|
|
||||||
int srcOffset = 0;
|
int srcOffset = 0;
|
||||||
// loop packet
|
// loop packet
|
||||||
{
|
for (int i = 0; i != PACKETS_PER_FRAME; ++i) {
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i != PACKETS_PER_FRAME; ++i) {
|
|
||||||
char packetData[packetSize];
|
char packetData[packetSize];
|
||||||
memset(packetData, 0, packetSize);
|
memset(packetData, 0, packetSize);
|
||||||
|
|
||||||
// set header
|
// set header
|
||||||
sls_detector_header *header =
|
sls_detector_header *header = (sls_detector_header *)(packetData);
|
||||||
(sls_detector_header *)(packetData);
|
|
||||||
header->detType = (uint16_t)myDetectorType;
|
header->detType = (uint16_t)myDetectorType;
|
||||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||||
header->frameNumber = frameNr + 1;
|
header->frameNumber = frameNr + 1;
|
||||||
@ -1805,11 +1775,10 @@ void *start_timer(void *arg) {
|
|||||||
|
|
||||||
sendUDPPacket(0, packetData, packetSize);
|
sendUDPPacket(0, packetData, packetSize);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
LOG(logINFO, ("Sent frame: %d\n", frameNr));
|
LOG(logINFO, ("Sent frame: %d\n", frameNr));
|
||||||
clock_gettime(CLOCK_REALTIME, &end);
|
clock_gettime(CLOCK_REALTIME, &end);
|
||||||
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 +
|
int64_t timeNs =
|
||||||
(end.tv_nsec - begin.tv_nsec));
|
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
|
||||||
|
|
||||||
// sleep for (period - exptime)
|
// sleep for (period - exptime)
|
||||||
if (frameNr < numFrames) { // if there is a next frame
|
if (frameNr < numFrames) { // if there is a next frame
|
||||||
@ -1818,7 +1787,6 @@ void *start_timer(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
closeUDPSocket(0);
|
closeUDPSocket(0);
|
||||||
|
|
||||||
@ -1948,10 +1916,6 @@ u_int32_t runBusy() {
|
|||||||
/* common */
|
/* common */
|
||||||
|
|
||||||
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||||
|
|
||||||
int idac, ichan;
|
|
||||||
int ret = OK;
|
|
||||||
|
|
||||||
LOG(logDEBUG1, ("Copying module\n"));
|
LOG(logDEBUG1, ("Copying module\n"));
|
||||||
|
|
||||||
if (srcMod->serialnumber >= 0) {
|
if (srcMod->serialnumber >= 0) {
|
||||||
@ -1987,18 +1951,18 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
|||||||
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
|
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
|
||||||
|
|
||||||
if (destMod->nchan != 0) {
|
if (destMod->nchan != 0) {
|
||||||
for (ichan = 0; ichan < (srcMod->nchan); ichan++) {
|
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
|
||||||
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
|
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
LOG(logINFO, ("Not Copying trimbits\n"));
|
LOG(logINFO, ("Not Copying trimbits\n"));
|
||||||
|
|
||||||
for (idac = 0; idac < (srcMod->ndac); idac++) {
|
for (int idac = 0; idac < (srcMod->ndac); idac++) {
|
||||||
if (*((srcMod->dacs) + idac) >= 0) {
|
if (*((srcMod->dacs) + idac) >= 0) {
|
||||||
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
|
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int calculateDataBytes() {
|
int calculateDataBytes() {
|
||||||
|
@ -1762,9 +1762,7 @@ int set_module(int file_des) {
|
|||||||
module.ndac = getNumberOfDACs();
|
module.ndac = getNumberOfDACs();
|
||||||
int ts = receiveModule(file_des, &module);
|
int ts = receiveModule(file_des, &module);
|
||||||
if (ts < 0) {
|
if (ts < 0) {
|
||||||
if (myChan != NULL)
|
|
||||||
free(myChan);
|
free(myChan);
|
||||||
if (myDac != NULL)
|
|
||||||
free(myDac);
|
free(myDac);
|
||||||
return printSocketReadError();
|
return printSocketReadError();
|
||||||
}
|
}
|
||||||
@ -1829,9 +1827,7 @@ int set_module(int file_des) {
|
|||||||
LOG(logDEBUG1, ("Settings: %d\n", retval));
|
LOG(logDEBUG1, ("Settings: %d\n", retval));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (myChan != NULL)
|
|
||||||
free(myChan);
|
free(myChan);
|
||||||
if (myDac != NULL)
|
|
||||||
free(myDac);
|
free(myDac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1895,9 +1891,7 @@ int get_module(int file_des) {
|
|||||||
if (ret != FAIL) {
|
if (ret != FAIL) {
|
||||||
ret = sendModule(file_des, &module);
|
ret = sendModule(file_des, &module);
|
||||||
}
|
}
|
||||||
if (myChan != NULL)
|
|
||||||
free(myChan);
|
free(myChan);
|
||||||
if (myDac != NULL)
|
|
||||||
free(myDac);
|
free(myDac);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -3934,7 +3928,6 @@ int program_fpga(int file_des) {
|
|||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
|
||||||
// free resources
|
// free resources
|
||||||
if (fpgasrc != NULL)
|
|
||||||
free(fpgasrc);
|
free(fpgasrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4009,7 +4002,6 @@ int program_fpga(int file_des) {
|
|||||||
stopWritingFPGAprogram(fp);
|
stopWritingFPGAprogram(fp);
|
||||||
|
|
||||||
// free resources
|
// free resources
|
||||||
if (fpgasrc != NULL)
|
|
||||||
free(fpgasrc);
|
free(fpgasrc);
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user