mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 08:10:02 +02:00
confirm if it is really moench detector;optimized code;option to start moench server with gotthard module
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@530 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
679a7dfd7e
commit
f006d289a3
@ -50,6 +50,7 @@ int masterMode=NO_MASTER, syncMode=NO_SYNCHRONIZATION, timingMode=AUTO_TIMING;
|
||||
|
||||
enum externalSignalFlag signals[4]={EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF};
|
||||
|
||||
int withGotthard = 0;
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
extern const int nChans;
|
||||
@ -177,6 +178,7 @@ int mapCSP0(void) {
|
||||
address = FIFO_DATA_REG_OFF;
|
||||
values=(u_int16_t*)(CSP0BASE+address*2);
|
||||
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
||||
printf("\n\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -256,7 +258,7 @@ int setPhaseShiftOnce(){
|
||||
|
||||
int cleanFifo(){
|
||||
u_int32_t addr, reg, val;
|
||||
printf("\nCleaning FIFO\n");
|
||||
printf("Cleaning FIFO\n");
|
||||
addr=ADC_SYNC_REG;
|
||||
|
||||
//88332214
|
||||
@ -295,7 +297,7 @@ int setDAQRegister()
|
||||
|
||||
//depended on pcb rev
|
||||
int tokenTiming = TOKEN_TIMING_REV2;
|
||||
if(bus_r(PCB_REV_REG)==1)
|
||||
if((bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)==1)
|
||||
tokenTiming= TOKEN_TIMING_REV1;
|
||||
|
||||
|
||||
@ -763,7 +765,7 @@ u_int32_t getFirmwareSVNVersion(){
|
||||
|
||||
// for fpga test
|
||||
u_int32_t testFpga(void) {
|
||||
printf("Test FPGA:\n");
|
||||
printf("Testing FPGA:\n");
|
||||
volatile u_int32_t val,addr,val2;
|
||||
int result=OK,i;
|
||||
//fixed pattern
|
||||
@ -812,8 +814,9 @@ u_int32_t testFpga(void) {
|
||||
{
|
||||
printf("----------------------------------------------------------------------------------------------");
|
||||
printf("\nATTEMPT 1000000: FPGA DUMMY REGISTER OK!!!\n");
|
||||
printf("----------------------------------------------------------------------------------------------\n");
|
||||
printf("----------------------------------------------------------------------------------------------");
|
||||
}
|
||||
printf("\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -825,7 +828,7 @@ u_int32_t testRAM(void) {
|
||||
allocateRAM();
|
||||
// while(i<100000) {
|
||||
memcpy(ram_values, values, dataBytes);
|
||||
printf ("Test RAM:\t%d: copied fifo %x to memory %x size %d\n",i++, (unsigned int)(values), (unsigned int)(ram_values), dataBytes);
|
||||
printf ("Testing RAM:\t%d: copied fifo %x to memory %x size %d\n",i++, (unsigned int)(values), (unsigned int)(ram_values), dataBytes);
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
@ -1192,7 +1195,7 @@ int initConfGain(int isettings,int val,int imod){
|
||||
|
||||
|
||||
int setADC(int adc){
|
||||
int reg,nchips,mask;
|
||||
int reg,nchips,mask,nchans;
|
||||
|
||||
if(adc==-1) ROI_flag=0;
|
||||
else ROI_flag=1;
|
||||
@ -1200,33 +1203,46 @@ int setADC(int adc){
|
||||
setDAQRegister();//token timing
|
||||
cleanFifo();//adc sync
|
||||
|
||||
//all adc
|
||||
if(adc==-1){
|
||||
//with gotthard module
|
||||
if(withGotthard){
|
||||
//set packet size
|
||||
ipPacketSize= DEFAULT_IP_PACKETSIZE;
|
||||
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
|
||||
//set channel mask
|
||||
nchips = GOTTHARDNCHIP;
|
||||
nchans = GOTTHARDNCHAN;
|
||||
mask = ACTIVE_ADC_MASK;
|
||||
}
|
||||
//1 adc
|
||||
|
||||
//with moench module all adc
|
||||
else{/* if(adc==-1){*/
|
||||
//set packet size
|
||||
ipPacketSize= DEFAULT_IP_PACKETSIZE;
|
||||
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
|
||||
//set channel mask
|
||||
nchips = NCHIP;
|
||||
nchans = NCHANS;
|
||||
mask = ACTIVE_ADC_MASK;
|
||||
}/*
|
||||
//with moench module 1 adc -- NOT IMPLEMENTED
|
||||
else{
|
||||
ipPacketSize= ADC1_IP_PACKETSIZE;
|
||||
udpPacketSize=ADC1_UDP_PACKETSIZE;
|
||||
//set channel mask
|
||||
nchips = NCHIPS_PER_ADC;
|
||||
nchans = GOTTHARDNCHAN;
|
||||
mask = 1<<adc;
|
||||
}
|
||||
}*/
|
||||
|
||||
//set channel mask
|
||||
reg = (GOTTHARDNCHAN*nchips)<<CHANNEL_OFFSET;
|
||||
reg = (nchans*nchips)<<CHANNEL_OFFSET;
|
||||
reg&=CHANNEL_MASK;
|
||||
reg|=(ACTIVE_ADC_MASK & mask);
|
||||
bus_w(CHIP_OF_INTRST_REG,reg);
|
||||
|
||||
#ifdef DDEBUG
|
||||
printf("Chip of Intrst Reg:%x\n",bus_r(CHIP_OF_INTRST_REG));
|
||||
#endif
|
||||
//#ifdef DDEBUG
|
||||
printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG));
|
||||
//#endif
|
||||
|
||||
adcConfigured = adc;
|
||||
|
||||
@ -1458,22 +1474,15 @@ u_int32_t runState(void) {
|
||||
int startStateMachine(){
|
||||
|
||||
//#ifdef VERBOSE
|
||||
printf("*******Starting State Machine***************\n");
|
||||
printf("*******Starting State Machine*******\n");
|
||||
//#endif
|
||||
cleanFifo();
|
||||
// fifoReset(); printf("Starting State Machine\n");
|
||||
// fifoReset();
|
||||
now_ptr=(char*)ram_values;
|
||||
#ifdef SHAREDMEMORY
|
||||
write_stop_sm(0);
|
||||
write_status_sm("Started");
|
||||
#endif
|
||||
/*
|
||||
#ifdef MCB_FUNCS
|
||||
setCSregister(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
#endif
|
||||
*/
|
||||
//putout("0000000000000000",ALLMOD);
|
||||
bus_w16(CONTROL_REG, START_ACQ_BIT | START_EXPOSURE_BIT);
|
||||
bus_w16(CONTROL_REG, 0x0);
|
||||
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
||||
@ -1485,9 +1494,9 @@ int startStateMachine(){
|
||||
|
||||
int stopStateMachine(){
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Stopping State Machine\n");
|
||||
#endif
|
||||
//#ifdef VERBOSE
|
||||
printf("*******Stopping State Machine*******\n");
|
||||
//#endif
|
||||
#ifdef SHAREDMEMORY
|
||||
write_stop_sm(1);
|
||||
write_status_sm("Stopped");
|
||||
@ -1691,39 +1700,6 @@ u_int32_t* decode_data(int *datain)
|
||||
|
||||
|
||||
int setDynamicRange(int dr) {
|
||||
/*
|
||||
int ow;
|
||||
int nm;
|
||||
|
||||
u_int32_t np=getProbes();
|
||||
#ifdef VERYVERBOSE
|
||||
printf("probes==%02x\n",np);
|
||||
#endif
|
||||
if (dr>0) {
|
||||
nm=setNMod(-1);
|
||||
if (dr==1) {
|
||||
dynamicRange=1;
|
||||
ow=5;
|
||||
} else if (dr<=4) {
|
||||
dynamicRange=4;
|
||||
ow=4;
|
||||
} else if (dr<=8) {
|
||||
dynamicRange=8;
|
||||
ow=3;
|
||||
} else if (dr<=16) {
|
||||
dynamicRange=16;
|
||||
ow=2;
|
||||
} else {
|
||||
dynamicRange=32;
|
||||
ow=0; //or 1?
|
||||
}
|
||||
setCSregister(ALLMOD);
|
||||
initChipWithProbes(0, ow,np, ALLMOD);
|
||||
putout("0000000000000000",ALLMOD);
|
||||
setNMod(nm);
|
||||
}
|
||||
*/
|
||||
|
||||
return getDynamicRange();
|
||||
}
|
||||
|
||||
@ -1733,46 +1709,6 @@ int setDynamicRange(int dr) {
|
||||
|
||||
|
||||
int getDynamicRange() {
|
||||
/*
|
||||
int dr;
|
||||
u_int32_t shiftin=bus_r(GET_SHIFT_IN_REG);
|
||||
u_int32_t outmux=(shiftin >> OUTMUX_OFF) & OUTMUX_MASK;
|
||||
u_int32_t probes=(shiftin >> PROBES_OFF) & PROBES_MASK;
|
||||
#ifdef VERYVERBOSE
|
||||
printf("%08x ",shiftin);
|
||||
printf("outmux=%02x probes=%d\n",outmux,probes);
|
||||
#endif
|
||||
|
||||
switch (outmux) {
|
||||
case 2:
|
||||
dr=16;
|
||||
break;
|
||||
case 4:
|
||||
dr=8;
|
||||
break;
|
||||
case 8:
|
||||
dr=4;
|
||||
break;
|
||||
case 16:
|
||||
dr=1;
|
||||
break;
|
||||
default:
|
||||
dr=32;
|
||||
}
|
||||
dynamicRange=dr;
|
||||
if (probes==0) {
|
||||
dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8;
|
||||
} else {
|
||||
dataBytes=nModX*nModY*NCHIP*NCHAN*4;///
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Number of data bytes %d - probes %d dr %d\n", dataBytes, probes, dr);
|
||||
#endif
|
||||
if (allocateRAM()==OK) {
|
||||
;
|
||||
} else
|
||||
printf("ram not allocated\n");
|
||||
*/
|
||||
dynamicRange=16;
|
||||
return dynamicRange;
|
||||
|
||||
@ -1891,6 +1827,7 @@ int allocateRAM() {
|
||||
|
||||
}
|
||||
int prepareADC(){
|
||||
printf("Preparing ADC\n");
|
||||
u_int32_t valw,codata,csmask;
|
||||
int i,cdx,ddx;
|
||||
cdx=0; ddx=1;
|
||||
@ -1902,11 +1839,17 @@ int prepareADC(){
|
||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_WRITE_REG,valw); //chip sel bar down
|
||||
for (i=0;i<24;i++) {
|
||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_WRITE_REG,valw);usleep(0); //cldwn
|
||||
#ifdef VERBOSE
|
||||
printf("DOWN 0x%x \n",valw);
|
||||
#endif
|
||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_WRITE_REG,valw); usleep(0); //write data (i)
|
||||
#ifdef VERBOSE
|
||||
printf("LOW 0x%x \n",valw);
|
||||
#endif
|
||||
valw=valw+(0x1<<cdx);bus_w(ADC_WRITE_REG,valw); usleep(0); //clkup
|
||||
#ifdef VERBOSE
|
||||
printf("up 0x%x \n",valw);
|
||||
#endif
|
||||
}
|
||||
|
||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
||||
|
@ -21,43 +21,73 @@ void error(char *msg)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno, b;
|
||||
char cmd[100];
|
||||
char cmd[500];
|
||||
int retval=OK;
|
||||
int sd, fd;
|
||||
int iarg;
|
||||
int checkType = 1;
|
||||
|
||||
|
||||
for(iarg=1; iarg<argc; iarg++){
|
||||
|
||||
if(!strcasecmp(argv[iarg],"-phaseshift")){
|
||||
if(argc==iarg+1){
|
||||
printf("No phaseshift given. Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
if ( sscanf(argv[iarg+1],"%d",&phase_shift)==0) {
|
||||
printf("could not decode phase shift\n");
|
||||
return 1;
|
||||
}
|
||||
argc=1;
|
||||
}
|
||||
|
||||
else if(!strcasecmp(argv[iarg],"-test")){
|
||||
if(argc==iarg+1){
|
||||
printf("No test condition given. Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
if(!strcasecmp(argv[iarg+1],"with_gotthard")){
|
||||
checkType = 0;
|
||||
}else{
|
||||
printf("could not decode test condition. Possible arguments: with_gotthard. Exiting\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (argc==1) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
|
||||
printf("opening control server on port %d\n",portno );
|
||||
system(cmd);
|
||||
b=1;
|
||||
} else {
|
||||
|
||||
//stop server
|
||||
if ((argc > 2) && (!strcasecmp(argv[2],"stopserver"))){
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
if ( sscanf(argv[1],"%d",&portno) ==0) {
|
||||
printf("could not open stop server: unknown port\n");
|
||||
return 1;
|
||||
}
|
||||
b=0;
|
||||
printf("opening stop server on port %d\n",portno);
|
||||
printf("\n\nStop Server\nOpening stop server on port %d\n",portno);
|
||||
}
|
||||
init_detector(b);
|
||||
|
||||
//control server
|
||||
else {
|
||||
portno = DEFAULT_PORTNO;
|
||||
if(checkType)
|
||||
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
|
||||
else
|
||||
sprintf(cmd,"%s %d stopserver -test with_gotthard &",argv[0],DEFAULT_PORTNO+1);
|
||||
printf("\n\nControl Server\nOpening control server on port %d\n",portno );
|
||||
|
||||
//printf("\n\ncmd:%s\n",cmd);
|
||||
system(cmd);
|
||||
b=1;
|
||||
}
|
||||
|
||||
|
||||
init_detector(b, checkType);
|
||||
|
||||
|
||||
sd=bindSocket(portno);
|
||||
|
||||
sockfd=sd;
|
||||
|
||||
|
||||
if (getServerError(sd)) {
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
|
@ -8,23 +8,23 @@
|
||||
|
||||
// Hardware definitions
|
||||
|
||||
#define NCHAN 160*160
|
||||
#define NCHAN (160*160)
|
||||
#define NCHIP 1
|
||||
#define NMAXMODX 1
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD NMAXMODX*NMAXMODY
|
||||
#define NMAXMOD (NMAXMODX*NMAXMODY)
|
||||
#define NDAC 8
|
||||
#define NADC 1
|
||||
|
||||
/**change this for the real moench chip*/
|
||||
/**when moench readout tested with gotthard module*/
|
||||
#define GOTTHARDNCHAN 128
|
||||
#define GOTTHARDNCHIP 10
|
||||
|
||||
|
||||
|
||||
|
||||
#define NCHANS NCHAN*NCHIP*NMAXMOD
|
||||
#define NDACS NDAC*NMAXMOD
|
||||
#define NCHANS (NCHAN*NCHIP*NMAXMOD)
|
||||
#define NDACS (NDAC*NMAXMOD)
|
||||
|
||||
#define NTRIMBITS 6
|
||||
#define NCOUNTBITS 24
|
||||
|
@ -53,39 +53,44 @@ char mess[1000];
|
||||
|
||||
int digitalTestBit = 0;
|
||||
|
||||
extern int withGotthard;
|
||||
|
||||
|
||||
int init_detector( int b) {
|
||||
#ifndef PICASSOD
|
||||
printf("This is a MOENCH detector with %d chips per module\n", NCHIP);
|
||||
#else
|
||||
printf("This is a PICASSO detector with %d chips per module\n", NCHIP);
|
||||
#endif
|
||||
|
||||
int init_detector(int b, int checkType) {
|
||||
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//testFpga();
|
||||
//confirm if it is really moench
|
||||
if(((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) != MOENCH_MODULE ){
|
||||
if(checkType){
|
||||
printf("This is a Gotthard detector. Exiting Moench Server.\n\n");
|
||||
exit(-1);
|
||||
}
|
||||
//no check required as specified in command line arguments
|
||||
else if(b){
|
||||
printf("***This is a GOTTHARD detector with %d chips per module***\n",GOTTHARDNCHIP);
|
||||
printf("***Assuming this to be a MOENCH detector***\n");
|
||||
}
|
||||
withGotthard = 1;
|
||||
}
|
||||
|
||||
if (b) {
|
||||
int reg;
|
||||
#ifdef MCB_FUNCS
|
||||
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
|
||||
initDetector();
|
||||
printf("\n***initdetector done*** \n\n");
|
||||
printf("Initializing Detector\n");
|
||||
#endif
|
||||
testFpga();
|
||||
testRAM();
|
||||
|
||||
//moench specific
|
||||
setPhaseShiftOnce();
|
||||
|
||||
prepareADC();
|
||||
setADC(-1); //already does setdaqreg and clean fifo
|
||||
printf("in chip of interes reg:%d\n",bus_r(CHIP_OF_INTRST_REG));
|
||||
int reg = /*NCHAN*40;*/(GOTTHARDNCHAN*GOTTHARDNCHIP)<<CHANNEL_OFFSET;
|
||||
reg&=CHANNEL_MASK;
|
||||
reg|=ACTIVE_ADC_MASK;
|
||||
bus_w(CHIP_OF_INTRST_REG,reg);
|
||||
printf("in chip of interes reg:%d\n",bus_r(CHIP_OF_INTRST_REG));
|
||||
setSettings(GET_SETTINGS,-1);
|
||||
|
||||
//Initialization
|
||||
setFrames(1);
|
||||
setTrains(1);
|
||||
@ -2279,6 +2284,10 @@ int set_roi(int file_des) {
|
||||
//#endif
|
||||
}
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
|
||||
|
||||
ret = FAIL;
|
||||
/* NOT IMPLEMENTED
|
||||
#ifdef MCB_FUNCS
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Detector locked by %s\n", lastClientIP);
|
||||
@ -2294,8 +2303,7 @@ int set_roi(int file_des) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
*/
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
ret=FORCE_UPDATE;
|
||||
|
@ -23,8 +23,7 @@ int sockfd;
|
||||
int function_table();
|
||||
|
||||
int decode_function(int);
|
||||
|
||||
int init_detector(int);
|
||||
int init_detector(int,int);
|
||||
|
||||
int M_nofunc(int);
|
||||
int exit_server(int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user