merge conflict removed, jungfrau server and eiger server re compiled

This commit is contained in:
2018-02-05 12:33:05 +01:00
24 changed files with 1213 additions and 158 deletions

View File

@@ -6,67 +6,68 @@
#endif
/* global variables */
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
#ifdef VERBOSE
if (numbitstosend == 16)
printf("Writing to SPI Register: 0x%04x\n",val);
else
printf("Writing to SPI Register: 0x%08x\n", val);
#endif
u_int32_t valw;
SPIChipSelect (valw, addr, csmask);
sendDataToSPI(valw, addr, val, numbitstosend, clkmask, digoutmask, digofset);
SPIChipDeselect(valw, addr, csmask, clkmask);
}
void SPIChipSelect (u_int32_t& valw, u_int32_t addr, u_int32_t csmask) {
void SPIChipSelect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask) {
// start point
valw = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, valw);
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, (*valw));
// chip sel bar down
valw &= ~csmask; /* todo with test: done a bit different, not with previous value */
bus_w (addr, valw);
(*valw) &= ~csmask; /* todo with test: done a bit different, not with previous value */
bus_w (addr, (*valw));
}
void SPIChipDeselect (u_int32_t& valw, u_int32_t addr, u_int32_t csmask, u_int32_t clkmask) {
void SPIChipDeselect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask, u_int32_t clkmask) {
// chip sel bar up
valw |= csmask; /* todo with test: not done for spi */
bus_w (addr, valw);
(*valw) |= csmask; /* todo with test: not done for spi */
bus_w (addr, (*valw));
//clk down
valw &= ~clkmask;
bus_w (addr, valw);
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
// stop point = start point of course
valw = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, valw);
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, (*valw));
}
void sendDataToSPI (u_int32_t& valw, u_int32_t addr, u_int32_t val, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
void sendDataToSPI (u_int32_t* valw, u_int32_t addr, u_int32_t val, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
int i = 0;
for (i = 0; i < numbitstosend; ++i) {
// clk down
valw &= ~clkmask;
bus_w (addr, valw);
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
// write data (i)
valw = ((valw & ~digoutmask) + // unset bit
(*valw) = (((*valw) & ~digoutmask) + // unset bit
(((val >> (numbitstosend - 1 - i)) & 0x1) << digofset)); // each bit from val starting from msb
bus_w (addr, valw);
bus_w (addr, (*valw));
// clk up
valw |= clkmask ;
bus_w (addr, valw);
(*valw) |= clkmask ;
bus_w (addr, (*valw));
}
}
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
#ifdef VERBOSE
if (numbitstosend == 16)
printf("Writing to SPI Register: 0x%04x\n",val);
else
printf("Writing to SPI Register: 0x%08x\n", val);
#endif
u_int32_t valw;
SPIChipSelect (&valw, addr, csmask);
sendDataToSPI(&valw, addr, val, numbitstosend, clkmask, digoutmask, digofset);
SPIChipDeselect(&valw, addr, csmask, clkmask);
}
#endif //COMMON_SERVER_FUNCTIONS_H

View File

@@ -37,6 +37,7 @@ u_int64_t getFirmwareVersion();
#ifdef MYTHEND
int64_t getModuleId(enum idMode arg, int imod);
#elif JUNGFRAUD
u_int64_t getFirmwareAPIVersion();
u_int16_t getHardwareVersionNumber();
u_int16_t getHardwareSerialNumber();
#endif
@@ -75,11 +76,13 @@ int powerChip (int on);
void cleanFifos();
void resetCore();
void resetPeripheral();
#endif
#ifdef MYTHEN3D
int getPhase(int i);
int configurePhase(int val, enum CLKINDEX i);
int configureFrequency(int val, int i);
#endif
#ifdef JUNGFRAUD
#elif JUNGFRAUD
int autoCompDisable(int on);
int adcPhase(int st);
int getPhase();
#endif
@@ -197,6 +200,9 @@ int calibratePedestal(int frames);
void resetPLL();
u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val);
void configurePll();
int setThresholdTemperature(int val);
int setTemperatureControl(int val);
int setTemperatureEvent(int val);
extern void eraseFlash(); // programfpga.h
extern int startWritingFPGAprogram(FILE** filefp); // programfpga.h
extern void stopWritingFPGAprogram(FILE* filefp); // programfpga.h
@@ -220,7 +226,9 @@ int setAllTrimbits(int val);
int getAllTrimbits();
int getBebFPGATemp();
int activate(int enable);
int setNetworkParameter(enum NETWORKINDEX mode, int value);
#endif
#if defined(JUNGFRAUD) || defined(EIGERD)
int setNetworkParameter(enum NETWORKINDEX mode, int value);
#endif

View File

@@ -12,7 +12,6 @@
#include <signal.h>
#include <string.h>
extern int sockfd;
@@ -30,14 +29,13 @@ int main(int argc, char *argv[]){
// subsequent read/write to socket gives error - must handle locally
signal(SIGPIPE, SIG_IGN);
// circumvent the basic tests
if(argc > 1) {
if(!strcasecmp(argv[1],"-debug")){
debugflag = 1;
argc=1;
}
}
// circumvent the basic tests
if(argc > 1) {
if(!strcasecmp(argv[1],"-debug")){
debugflag = 1;
argc=1;
}
}
#ifdef STOP_SERVER
char cmd[100];
@@ -85,8 +83,10 @@ int main(int argc, char *argv[]){
printf("function table assigned \n");
#endif
printf("\nReady...\n\n");
if (b)
printf("\nControl Server Ready...\n\n");
else
printf("\nStop Server Ready...\n\n");
/* waits for connection */
while(retval!=GOODBYE) {

View File

@@ -50,7 +50,7 @@ int printSocketReadError() {
}
void basictests(int flag) {
debugflag = flag;
debugflag = flag;
#ifdef SLS_DETECTOR_FUNCTION_LIST
checkFirmwareCompatibility(debugflag);
#endif
@@ -64,7 +64,7 @@ void init_detector(int controlserver) {
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (controlserver) {
isControlServer = 1;
isControlServer = 1;
initControlServer();
}
else initStopServer();
@@ -183,6 +183,11 @@ const char* getFunctionName(enum detFuncs func) {
case F_ACTIVATE: return "F_ACTIVATE";
case F_PREPARE_ACQUISITION: return "F_PREPARE_ACQUISITION";
case F_CLEANUP_ACQUISITION: return "F_CLEANUP_ACQUISITION";
case F_THRESHOLD_TEMP: return "F_THRESHOLD_TEMP";
case F_TEMP_CONTROL: return "F_TEMP_CONTROL";
case F_TEMP_EVENT: return "F_TEMP_EVENT";
case F_AUTO_COMP_DISABLE: return "F_AUTO_COMP_DISABLE";
default: return "Unknown Function";
}
}
@@ -261,6 +266,10 @@ void function_table() {
flist[F_ACTIVATE] = &set_activate;
flist[F_PREPARE_ACQUISITION] = &prepare_acquisition;
flist[F_CLEANUP_ACQUISITION] = &cleanup_acquisition;
flist[F_THRESHOLD_TEMP] = &threshold_temp;
flist[F_TEMP_CONTROL] = &temp_control;
flist[F_TEMP_EVENT] = &temp_event;
flist[F_AUTO_COMP_DISABLE] = &auto_comp_disable;
// check
if (NUM_DET_FUNCTIONS >= TOO_MANY_FUNCTIONS_DEFINED) {
@@ -4187,11 +4196,6 @@ int set_all_trimbits(int file_des){
int set_ctb_pattern(int file_des) {
int ret=OK,ret1=OK;
int n=0;
int retval=-1;
int mode = -1;
int addr = -1, level = -1, nl = -1, start = -1, stop = -1;
uint64_t word = -1,retval64 = -1, t = -1;
sprintf(mess,"Could not set pattern\n");
#ifndef MYTHEN3D
@@ -4212,7 +4216,13 @@ int set_ctb_pattern(int file_des) {
return ret;
#endif
#else
int retval=-1;
int mode = -1;
int addr = -1, level = -1, nl = -1, start = -1, stop = -1;
uint64_t word = -1,retval64 = -1, t = -1;
n = receiveDataOnly(file_des, &mode, sizeof(mode));
printf("pattern mode is %d\n",mode);
@@ -4223,7 +4233,7 @@ int set_ctb_pattern(int file_des) {
n = receiveDataOnly(file_des,&word,sizeof(word));
ret=OK;
printf("pattern addr is %d %x\n",addr, word);
printf("pattern addr is %d %llx\n",addr, word);
switch (addr) {
case -1:
retval64=writePatternIOControl(word);
@@ -4359,6 +4369,7 @@ int set_ctb_pattern(int file_des) {
// return ok / fail
return ret;
#endif
}
@@ -4763,7 +4774,7 @@ int set_network_parameter(int file_des) {
int retval=-1;
sprintf(mess,"set network parameter failed\n");
#ifndef EIGERD
#if !defined(EIGERD) && !defined(JUNGFRAUD)
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
@@ -4784,7 +4795,7 @@ int set_network_parameter(int file_des) {
if (n < 0) return printSocketReadError();
// execute action
if (differentClients && lockStatus && value<0) {
if (differentClients && lockStatus && value >= 0) {
ret = FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
cprintf(RED, "Warning: %s", mess);
@@ -4795,17 +4806,27 @@ int set_network_parameter(int file_des) {
printf("setting network parameter mode %d to %d\n",(int)mode,value);
#endif
switch (mode) {
#ifdef EIGERD
case FLOW_CONTROL_10G:
index = FLOWCTRL_10G;
break;
case DETECTOR_TXN_DELAY_LEFT:
index = TXN_LEFT;
break;
case DETECTOR_TXN_DELAY_RIGHT:
index = TXN_RIGHT;
break;
#endif
case DETECTOR_TXN_DELAY_FRAME:
index = TXN_FRAME;
break;
case FLOW_CONTROL_10G:
index = FLOWCTRL_10G;
#ifdef JUNGFRAUD
if (value > MAX_TIMESLOT_VAL) {
ret=FAIL;
sprintf(mess,"Transmission delay %d should be in range: 0 - %d\n", value, MAX_TIMESLOT_VAL);
cprintf(RED, "Warning: %s", mess);
}
#endif
break;
default:
ret=FAIL;
@@ -4963,9 +4984,9 @@ int program_fpga(int file_des) {
#ifdef VERY_VERBOSE
printf("Done with program receiving command\n");
#endif
if (isControlServer)
basictests(debugflag);
init_detector(isControlServer);
if (isControlServer)
basictests(debugflag);
init_detector(isControlServer);
}
#endif
if (ret==OK)
@@ -5011,9 +5032,9 @@ int reset_fpga(int file_des) {
}
#ifdef SLS_DETECTOR_FUNCTION_LIST
else {
if (isControlServer)
basictests(debugflag);
init_detector(isControlServer);
if (isControlServer)
basictests(debugflag);
initControlServer(isControlServer);
ret = FORCE_UPDATE;
}
#endif
@@ -5074,7 +5095,10 @@ int power_chip(int file_des) {
ret=OK;
} else {
ret=FAIL;
sprintf(mess,"Powering chip failed, wrote %d but read %d\n", arg, retval);
if(setTemperatureEvent(-1) == 1)
sprintf(mess,"Powering chip failed due to over-temperature event. Clear event & power chip again. Wrote %d, read %d \n", arg, retval);
else
sprintf(mess,"Powering chip failed, wrote %d but read %d\n", arg, retval);
cprintf(RED, "Warning: %s", mess);
}
}
@@ -5250,3 +5274,255 @@ int cleanup_acquisition(int file_des) {
}
int threshold_temp(int file_des) {
int ret=OK,ret1=OK;
int n=0;
int retval=-1;
sprintf(mess,"could not set/get threshold temperature\n");
#ifndef JUNGFRAUD
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
ret = FAIL;
sprintf(mess,"Function (Threshold Temp) is not implemented for this detector\n");
cprintf(RED, "%s", mess);
#else
int arg[2]={-1,-1};
int val=-1;
// receive arguments
n = receiveData(file_des,arg,sizeof(arg),INT32);
if (n < 0) return printSocketReadError();
val=arg[0];
//ignoring imod
if (val > MAX_THRESHOLD_TEMP_VAL) {
ret=FAIL;
sprintf(mess,"Threshold Temp %d should be in range: 0 - %d\n", val, MAX_THRESHOLD_TEMP_VAL);
cprintf(RED, "Warning: %s", mess);
}
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (ret==OK) {
#ifdef VERBOSE
printf("Setting Threshold Temperature to %d\n", val);
#endif
retval=setThresholdTemperature(val);
}
#endif
#ifdef VERBOSE
printf("Threshold temperature is %d\n", retval);
#endif
if (ret==OK && differentClients && val >= 0)
ret=FORCE_UPDATE;
#endif
// ret could be swapped during sendData
ret1 = ret;
// send ok / fail
n = sendData(file_des,&ret1,sizeof(ret),INT32);
// send return argument
if (ret!=FAIL) {
n += sendData(file_des,&retval,sizeof(retval),INT32);
} else {
n += sendData(file_des,mess,sizeof(mess),OTHER);
}
// return ok / fail
return ret;
}
int temp_control(int file_des) {
int ret=OK,ret1=OK;
int n=0;
int retval=-1;
sprintf(mess,"could not set/get temperature control\n");
#ifndef JUNGFRAUD
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
ret = FAIL;
sprintf(mess,"Function (Temperature control) is not implemented for this detector\n");
cprintf(RED, "%s", mess);
#else
int arg[2]={-1,-1};
int val=-1;
// receive arguments
n = receiveData(file_des,arg,sizeof(arg),INT32);
if (n < 0) return printSocketReadError();
val=arg[0];
//ignoring imod
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (ret==OK) {
#ifdef VERBOSE
printf("Setting Temperature control to %d\n", val);
#endif
retval=setTemperatureControl(val);
}
#endif
#ifdef VERBOSE
printf("Temperature control is %d\n", retval);
#endif
if (ret==OK && differentClients && val >= 0)
ret=FORCE_UPDATE;
#endif
// ret could be swapped during sendData
ret1 = ret;
// send ok / fail
n = sendData(file_des,&ret1,sizeof(ret),INT32);
// send return argument
if (ret!=FAIL) {
n += sendData(file_des,&retval,sizeof(retval),INT32);
} else {
n += sendData(file_des,mess,sizeof(mess),OTHER);
}
// return ok / fail
return ret;
}
int temp_event(int file_des) {
int ret=OK,ret1=OK;
int n=0;
int retval=-1;
sprintf(mess,"could not set/get temperature event\n");
#ifndef JUNGFRAUD
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
ret = FAIL;
sprintf(mess,"Function (Temperature Event) is not implemented for this detector\n");
cprintf(RED, "%s", mess);
#else
int arg[2]={-1,-1};
int val=-1;
// receive arguments
n = receiveData(file_des,arg,sizeof(arg),INT32);
if (n < 0) return printSocketReadError();
val=arg[0];
//ignoring imod
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (ret==OK) {
#ifdef VERBOSE
printf("Setting Temperature Event to %d\n", val);
#endif
retval=setTemperatureEvent(val);
}
#endif
#ifdef VERBOSE
printf("Temperature Event is %d\n", retval);
#endif
if (ret==OK && differentClients && val >= 0)
ret=FORCE_UPDATE;
#endif
// ret could be swapped during sendData
ret1 = ret;
// send ok / fail
n = sendData(file_des,&ret1,sizeof(ret),INT32);
// send return argument
if (ret!=FAIL) {
n += sendData(file_des,&retval,sizeof(retval),INT32);
} else {
n += sendData(file_des,mess,sizeof(mess),OTHER);
}
// return ok / fail
return ret;
}
int auto_comp_disable(int file_des) {
int ret=OK,ret1=OK;
int n=0;
int retval=-1;
sprintf(mess,"auto comp disable failed\n");
#ifndef JUNGFRAUD
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
ret = FAIL;
sprintf(mess,"Function (Auto Comp Disable) is not implemented for this detector\n");
cprintf(RED, "%s", mess);
#else
//to receive any arguments
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
ret = FAIL;
sprintf(mess,"Function (Auto Comp Disable) is not yet implemented for this detector\n");
cprintf(RED, "%s", mess);
/* will be connected after teh fpga upgrade
// receive arguments
int arg=-1;
n = receiveData(file_des,&arg,sizeof(arg),INT32);
if (n < 0) return printSocketReadError();
// execute action
if (differentClients && lockStatus && arg!=-1) {
ret = FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
cprintf(RED, "Warning: %s", mess);
}
#ifdef SLS_DETECTOR_FUNCTION_LIST
else {
#ifdef VERBOSE
printf("Auto Comp Disable to %d\n", arg);
#endif
retval=autoCompDisable(arg);
#ifdef VERBOSE
printf("Auto comp disable set to: %d\n",retval);
#endif
if (retval==arg || arg<0) {
ret=OK;
} else {
ret=FAIL;
sprintf(mess,"Atuo Comp Disable failed, wrote %d but read %d\n", arg, retval);
cprintf(RED, "Warning: %s", mess);
}
}
#endif
if (ret==OK && differentClients)
ret=FORCE_UPDATE;
*/
#endif
// ret could be swapped during sendData
ret1 = ret;
// send ok / fail
n = sendData(file_des,&ret1,sizeof(ret),INT32);
// send return argument
if (ret==FAIL) {
n += sendData(file_des,mess,sizeof(mess),OTHER);
} else
n += sendData(file_des,&retval,sizeof(retval),INT32);
// return ok / fail
return ret;
}

View File

@@ -88,6 +88,9 @@ int power_chip(int);
int set_activate(int);
int prepare_acquisition(int);
int cleanup_acquisition(int);
int threshold_temp(int);
int temp_control(int);
int temp_event(int);
int auto_comp_disable(int);
#endif