nios, for variable delcaration in loop

This commit is contained in:
maliakal_d 2020-05-08 09:39:36 +02:00
parent 9b21f44d94
commit 2f11dbc2c9
3 changed files with 149 additions and 233 deletions

View File

@ -217,9 +217,8 @@ int testBus() {
int ret = OK;
u_int32_t addr = DTA_OFFSET_REG;
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);
if (i * 100 != bus_r(addr)) {
LOG(logERROR,
@ -375,26 +374,23 @@ void setupDetector() {
delayReg = 0;
numBurstsReg = 1;
burstPeriodReg = 0;
{
int i, j;
for (i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0;
for (int i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0;
}
for (int i = 0; i < NDAC; ++i) {
dacValues[i] = 0;
}
for (int i = 0; i < ONCHIP_NDAC; ++i) {
for (int j = 0; j < NCHIP; ++j) {
onChipdacValues[i][j] = -1;
}
for (i = 0; i < NDAC; ++i) {
dacValues[i] = 0;
}
for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NCHAN; ++j) {
vetoReference[i][j] = 0;
}
for (i = 0; i < ONCHIP_NDAC; ++i) {
for (j = 0; j < NCHIP; ++j) {
onChipdacValues[i][j] = -1;
}
}
for (i = 0; i < NCHIP; ++i) {
for (j = 0; j < NCHAN; ++j) {
vetoReference[i][j] = 0;
}
for (j = 0; j < NADC; ++j) {
adcConfiguration[i][j] = 0;
}
for (int j = 0; j < NADC; ++j) {
adcConfiguration[i][j] = 0;
}
}
#ifdef VIRTUAL
@ -647,9 +643,8 @@ int readConfigFile() {
adcmax = iadc + 1;
}
int i, j;
for (i = chipmin; i < chipmax; ++i) {
for (j = adcmin; j < adcmax; ++j) {
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value;
++nadcRead;
}
@ -776,13 +771,10 @@ int readConfigFile() {
nadcRead, NADC * NCHIP);
}
}
{
int i = 0, j = 0;
for (i = 0; i < NCHIP; ++i) {
for (j = 0; j < NADC; ++j) {
LOG(logDEBUG2, ("adc read %d %d: 0x%02hhx\n", i, j,
adcConfiguration[i][j]));
}
for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NADC; ++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
if (chipIndex == -1) {
int ichip = 0;
for (ichip = 0; ichip < NCHIP; ++ichip) {
for (int ichip = 0; ichip < NCHIP; ++ichip) {
onChipdacValues[ind][ichip] = val;
}
}
@ -1160,9 +1151,8 @@ int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex) {
// all chips
if (chipIndex == -1) {
int retval = onChipdacValues[ind][0];
int ichip = 0;
// 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) {
return -1;
}
@ -1641,8 +1631,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
// Remembering old phases in degrees
int oldPhases[NUM_CLOCKS];
{
int i = 0;
for (i = 0; i < NUM_CLOCKS; ++i) {
for (int i = 0; i < NUM_CLOCKS; ++i) {
oldPhases[i] = getPhase(i, 1);
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
clock_names[ind], ind, oldPhases[i]));
@ -1673,16 +1662,13 @@ int setClockDivider(enum CLKINDEX ind, int val) {
}
// set the phase in degrees (reset by pll)
{
int i = 0;
for (i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
LOG(logINFO,
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
for (int i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
LOG(logINFO,
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
}
return OK;
@ -1711,8 +1697,8 @@ int setInjectChannel(int offset, int increment) {
char buffer[17];
memset(buffer, 0, sizeof(buffer));
int startCh = 4; // 4 due to padding
int ich = 0;
for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) {
for (int ich = startCh + offset; ich < startCh + NCHAN;
ich = ich + increment) {
int byteIndex = ich / 8;
int bitIndex = ich % 8;
buffer[byteIndex] |= (1 << (8 - 1 - bitIndex));
@ -1741,8 +1727,7 @@ int setVetoReference(int gainIndex, int value) {
gainIndex, value));
int vals[NCHAN];
memset(vals, 0, sizeof(vals));
int ich = 0;
for (ich = 0; ich < NCHAN; ++ich) {
for (int ich = 0; ich < NCHAN; ++ich) {
vals[ich] = value;
}
return setVetoPhoton(-1, gainIndex, vals);
@ -1770,8 +1755,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
return FAIL;
}
LOG(logDEBUG2, ("Adding gain bits\n"));
int i = 0;
for (i = 0; i < NCHAN; ++i) {
for (int i = 0; i < NCHAN; ++i) {
values[i] |= gainValue;
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];
memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes
int ich = 0;
for (ich = 0; ich < NCHAN; ++ich) {
for (int ich = 0; ich < NCHAN; ++ich) {
// loop through all bits in a value
int iBit = 0;
for (iBit = 0; iBit < lenDataBitsPerchannel; ++iBit) {
@ -1803,10 +1786,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
memset(buffer, 0, len);
offset = 0;
// loop through buffer elements
for (ich = 0; ich < len; ++ich) {
for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element
int iBit = 0;
for (iBit = 0; iBit < 8; ++iBit) {
for (int iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
}
}
@ -1820,10 +1802,8 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
// all chips
if (chipIndex == -1) {
int ichip = 0;
int ichan = 0;
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (ichip = 0; ichip < NCHIP; ++ichip) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichip = 0; ichip < NCHIP; ++ichip) {
vetoReference[ichip][ichan] = values[ichan];
}
}
@ -1831,8 +1811,7 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
// specific chip
else {
int ichan = 0;
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
vetoReference[chipIndex][chipIndex] = values[ichan];
;
}
@ -1842,10 +1821,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values) {
int getVetoPhoton(int chipIndex, int *retvals) {
if (chipIndex == -1) {
int i = 0, j = 0;
for (i = 0; i < NCHAN; ++i) {
for (int i = 0; i < NCHAN; ++i) {
int val = vetoReference[0][i];
for (j = 1; j < NCHIP; ++j) {
for (int j = 1; j < NCHIP; ++j) {
if (vetoReference[j][i] != val) {
LOG(logERROR,
("Get vet photon fail for chipIndex:%d. Different "
@ -1876,14 +1854,11 @@ int configureSingleADCDriver(int chipIndex) {
memcpy(values, adcConfiguration + ind * NADC, NADC);
// change adc values if continuous mode
{
int i = 0;
for (i = 0; i < NADC; ++i) {
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
for (int i = 0; i < NADC; ++i) {
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
}
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
@ -1896,11 +1871,9 @@ int configureSingleADCDriver(int chipIndex) {
uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes
int ich = 0;
for (ich = 0; ich < NADC; ++ich) {
for (int ich = 0; ich < NADC; ++ich) {
// loop through all bits in a value
int iBit = 0;
for (iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
for (int iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
commandBytes[offset++] =
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
}
@ -1912,10 +1885,9 @@ int configureSingleADCDriver(int chipIndex) {
memset(buffer, 0, len);
offset = 0;
// loop through buffer elements
for (ich = 0; ich < len; ++ich) {
for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element
int iBit = 0;
for (iBit = 0; iBit < 8; ++iBit) {
for (int iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
}
}
@ -1934,23 +1906,19 @@ int configureADC() {
LOG(logINFO, ("Configuring ADC \n"));
int equal = 1;
{
int i = 0, j = 0;
for (i = 0; i < NADC; ++i) {
int val = adcConfiguration[0][i];
for (j = 1; j < NCHIP; ++j) {
if (adcConfiguration[j][i] != val) {
equal = 0;
break;
}
for (int i = 0; i < NADC; ++i) {
int val = adcConfiguration[0][i];
for (int j = 1; j < NCHIP; ++j) {
if (adcConfiguration[j][i] != val) {
equal = 0;
break;
}
}
}
if (equal) {
return configureSingleADCDriver(-1);
} else {
int i = 0;
for (i = 0; i < NCHIP; ++i) {
for (int i = 0; i < NCHIP; ++i) {
if (configureSingleADCDriver(i) == FAIL) {
return FAIL;
}
@ -2075,10 +2043,8 @@ int setBurstMode(enum burstMode burst) {
uint8_t commandBytes[lenTotalBits];
memset(commandBytes, 0, sizeof(commandBytes));
int offset = padding; // bit offset for commandbytes
int ich = 0;
// loop through all bits in a value
int iBit = 0;
for (iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
for (int iBit = 0; iBit < ASIC_GLOBAL_SETT_MAX_BITS; ++iBit) {
commandBytes[offset++] =
((value >> (ASIC_GLOBAL_SETT_MAX_BITS - 1 - iBit)) & 0x1);
}
@ -2089,10 +2055,9 @@ int setBurstMode(enum burstMode burst) {
memset(buffer, 0, len);
offset = 0;
// loop through buffer elements
for (ich = 0; ich < len; ++ich) {
for (int ich = 0; ich < len; ++ich) {
// loop through each bit in buffer element
int iBit = 0;
for (iBit = 0; iBit < 8; ++iBit) {
for (int iBit = 0; iBit < 8; ++iBit) {
buffer[ich] |= (commandBytes[offset++] << (8 - 1 - iBit));
}
}
@ -2235,25 +2200,20 @@ void *start_timer(void *arg) {
// Generate data
char imageData[imagesize];
memset(imageData, 0, imagesize);
{
int i = 0;
for (i = 0; i < imagesize; i += sizeof(uint16_t)) {
*((uint16_t *)(imageData + i)) = i;
}
for (int i = 0; i < imagesize; i += sizeof(uint16_t)) {
*((uint16_t *)(imageData + i)) = i;
}
{
int repeatNr = 0;
int frameHeaderNr = 0;
// loop over number of repeats
for (repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
for (int repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
struct timespec rbegin, rend;
clock_gettime(CLOCK_REALTIME, &rbegin);
int frameNr = 0;
// 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
virtual_stop = ComVirtual_getStop();

View File

@ -208,9 +208,8 @@ int testBus() {
int ret = OK;
u_int32_t addr = DTA_OFFSET_REG;
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);
if (i * 100 != bus_r(addr)) {
LOG(logERROR,
@ -365,14 +364,12 @@ void allocateDetectorStructureMemory() {
// thisSettings = UNINITIALIZED;
// initialize dacs
int idac = 0;
for (idac = 0; idac < (detectorModules)->ndac; ++idac) {
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
detectorDacs[idac] = 0;
}
// if trimval requested, should return -1 to acknowledge unknown
int ichan = 0;
for (ichan = 0; ichan < (detectorModules->nchan); ichan++) {
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = -1;
}
}
@ -390,11 +387,8 @@ void setupDetector() {
highvoltage = 0;
trimmingPrint = logINFO;
{
int i;
for (i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0;
}
for (int i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0;
}
#ifdef VIRTUAL
virtual_status = 0;
@ -441,9 +435,8 @@ int setDefaultDacs() {
int ret = OK;
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{
int i = 0;
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);
if (detectorDacs[i] != defaultvals[i]) {
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i,
@ -551,18 +544,14 @@ int setModule(sls_detector_module myMod, char *mess) {
*/
// dacs
{
int i = 0;
for (i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
if (myMod.dacs[i] != detectorDacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n",
i);
LOG(logERROR, (mess));
// setSettings(UNDEFINED);
// LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
for (int i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
if (myMod.dacs[i] != detectorDacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
LOG(logERROR, (mess));
// setSettings(UNDEFINED);
// LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
@ -602,8 +591,7 @@ int setTrimbits(int *trimbits) {
LOG(logINFOBLUE, ("Setting trimbits\n"));
// validate
int ichan = 0;
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
if (trimbits[ichan] < 0 || trimbits[ichan] > 63) {
LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid\n",
trimbits[ichan], ichan));
@ -615,8 +603,7 @@ int setTrimbits(int *trimbits) {
uint64_t patword = 0;
int iaddr = 0;
int ichip = 0;
for (ichip = 0; ichip < NCHIP; ichip++) {
for (int ichip = 0; ichip < NCHIP; ichip++) {
LOG(logINFOBLUE, (" Chip %d\n", ichip));
iaddr = 0;
patword = 0;
@ -733,8 +720,7 @@ int setTrimbits(int *trimbits) {
}
// copy trimbits locally
ichan = 0;
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
detectorChans[ichan] = trimbits[ichan];
}
trimmingPrint = logINFO;
@ -743,8 +729,7 @@ int setTrimbits(int *trimbits) {
int setAllTrimbits(int val) {
int *trimbits = malloc(sizeof(int) * NCHAN);
int ichan = 0;
for (ichan = 0; ichan < NCHAN; ++ichan) {
for (int ichan = 0; ichan < NCHAN; ++ichan) {
trimbits[ichan] = val;
}
if (setTrimbits(trimbits) == FAIL) {
@ -761,10 +746,9 @@ int setAllTrimbits(int val) {
}
int getAllTrimbits() {
int ichan = 0;
int value = detectorChans[0];
if (detectorModules) {
for (ichan = 0; ichan < NCHAN; ichan++) {
for (int ichan = 0; ichan < NCHAN; ichan++) {
if (detectorChans[ichan] != value) {
value = -1;
break;
@ -1644,13 +1628,10 @@ int setClockDivider(enum CLKINDEX ind, int val) {
// Remembering old phases in degrees
int oldPhases[NUM_CLOCKS];
{
int i = 0;
for (i = 0; i < NUM_CLOCKS; ++i) {
oldPhases[i] = getPhase(i, 1);
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
clock_names[ind], ind, oldPhases[i]));
}
for (int i = 0; i < NUM_CLOCKS; ++i) {
oldPhases[i] = getPhase(i, 1);
LOG(logDEBUG1, ("\tRemembering %s clock (%d) phase: %d degrees\n",
clock_names[ind], ind, oldPhases[i]));
}
// Calculate and set output frequency
@ -1672,16 +1653,13 @@ int setClockDivider(enum CLKINDEX ind, int val) {
}
// set the phase in degrees (reset by pll)
{
int i = 0;
for (i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
LOG(logINFO,
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
for (int i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
LOG(logINFO,
("\tCorrecting %s clock (%d) phase from %d to %d degrees\n",
clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
}
return OK;
@ -1754,68 +1732,58 @@ void *start_timer(void *arg) {
// Generate data
char imageData[imagesize];
memset(imageData, 0, imagesize);
{
int i = 0;
for (i = 0; i < imagesize; i += sizeof(uint8_t)) {
*((uint8_t *)(imageData + i)) = i;
}
for (int i = 0; i < imagesize; i += sizeof(uint8_t)) {
*((uint8_t *)(imageData + i)) = i;
}
// Send data
{
int frameNr = 1;
// loop over number of frames
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
// loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
// check if virtual_stop is high
if (virtual_stop == 1) {
break;
}
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
// check if virtual_stop is high
if (virtual_stop == 1) {
break;
}
// sleep for exposure time
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);
usleep(expUs);
// sleep for exposure time
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);
usleep(expUs);
int srcOffset = 0;
// loop packet
{
int i = 0;
for (i = 0; i != PACKETS_PER_FRAME; ++i) {
char packetData[packetSize];
memset(packetData, 0, packetSize);
int srcOffset = 0;
// loop packet
for (int i = 0; i != PACKETS_PER_FRAME; ++i) {
char packetData[packetSize];
memset(packetData, 0, packetSize);
// set header
sls_detector_header *header =
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr + 1;
header->packetNumber = i;
header->modId = 0;
header->row = detPos[X];
header->column = detPos[Y];
// set header
sls_detector_header *header = (sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr + 1;
header->packetNumber = i;
header->modId = 0;
header->row = detPos[X];
header->column = detPos[Y];
// fill data
memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize);
srcOffset += dataSize;
// fill data
memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize);
srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize);
}
}
LOG(logINFO, ("Sent frame: %d\n", frameNr));
clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec));
sendUDPPacket(0, packetData, packetSize);
}
LOG(logINFO, ("Sent frame: %d\n", frameNr));
clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs =
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame
if (periodNs > timeNs) {
usleep((periodNs - timeNs) / 1000);
}
// sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame
if (periodNs > timeNs) {
usleep((periodNs - timeNs) / 1000);
}
}
}
@ -1948,10 +1916,6 @@ u_int32_t runBusy() {
/* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int idac, ichan;
int ret = OK;
LOG(logDEBUG1, ("Copying module\n"));
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));
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);
}
} else
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) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return ret;
return OK;
}
int calculateDataBytes() {

View File

@ -1762,10 +1762,8 @@ int set_module(int file_des) {
module.ndac = getNumberOfDACs();
int ts = receiveModule(file_des, &module);
if (ts < 0) {
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
free(myChan);
free(myDac);
return printSocketReadError();
}
LOG(logDEBUG1, ("module register is %d, nchan %d, nchip %d, "
@ -1829,10 +1827,8 @@ int set_module(int file_des) {
LOG(logDEBUG1, ("Settings: %d\n", retval));
#endif
}
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
free(myChan);
free(myDac);
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
@ -1895,10 +1891,8 @@ int get_module(int file_des) {
if (ret != FAIL) {
ret = sendModule(file_des, &module);
}
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
free(myChan);
free(myDac);
return ret;
}
@ -3934,8 +3928,7 @@ int program_fpga(int file_des) {
Server_SendResult(file_des, INT32, NULL, 0);
// free resources
if (fpgasrc != NULL)
free(fpgasrc);
free(fpgasrc);
}
#else // jungfrau, ctb, moench
@ -4009,8 +4002,7 @@ int program_fpga(int file_des) {
stopWritingFPGAprogram(fp);
// free resources
if (fpgasrc != NULL)
free(fpgasrc);
free(fpgasrc);
if (fp != NULL)
fclose(fp);