mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-05 17:40:40 +02:00
jungfrau server making it uniform, left to do: register confirmation and server_defs
This commit is contained in:
parent
35631c0abb
commit
1fae912cb2
@ -403,7 +403,13 @@ int sendChip(int file_des, sls_detector_chip *myChip) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
return sendModuleGeneral(file_des, myMod, 1);
|
||||
}
|
||||
|
||||
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
|
||||
int ts=0;
|
||||
#ifdef VERBOSE
|
||||
int idac;
|
||||
@ -421,11 +427,12 @@ int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
ts+=sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=sendData(file_des,myMod->dacs,sizeof(myMod->ndac),OTHER);
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
ts+=sendData(file_des,myMod->adcs,sizeof(myMod->nadc),OTHER);
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
|
||||
#endif
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(sendAll){
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
|
||||
}
|
||||
ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
@ -438,21 +445,22 @@ int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
for (idac=0; idac< nDacs; idac++)
|
||||
printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]);
|
||||
#endif
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
ts+= sendData(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(sendAll){
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||
#endif
|
||||
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg);
|
||||
@ -513,7 +521,12 @@ int receiveChip(int file_des, sls_detector_chip* myChip) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
return receiveModuleGeneral(file_des,myMod,1);
|
||||
}
|
||||
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) {
|
||||
int ts=0;
|
||||
dacs_t *dacptr=myMod->dacs;
|
||||
dacs_t *adcptr=myMod->adcs;
|
||||
@ -534,11 +547,12 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
ts+=receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=receiveData(file_des,myMod->dacs,sizeof(myMod->ndac),INT32);
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
ts+=receiveData(file_des,myMod->adcs,sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
|
||||
#endif
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(receiveAll){
|
||||
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
|
||||
}
|
||||
ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
@ -606,7 +620,6 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
if (nadcdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs,INT32);
|
||||
#ifdef VERBOSE
|
||||
@ -621,34 +634,38 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chipptr=(int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(receiveAll){
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=(int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
} else {
|
||||
chipptr=(int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=(int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg);
|
||||
#endif
|
||||
|
@ -42,9 +42,10 @@ int getServerError(int socketDescriptor);
|
||||
int sendChannel(int file_des, sls_detector_channel *myChan);
|
||||
int sendChip(int file_des, sls_detector_chip *myChip);
|
||||
int sendModule(int file_des, sls_detector_module *myMod);
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll);
|
||||
int receiveChannel(int file_des, sls_detector_channel *myChan);
|
||||
int receiveChip(int file_des, sls_detector_chip* myChip);
|
||||
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||
|
||||
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll);
|
||||
|
||||
#endif
|
||||
|
@ -16,7 +16,7 @@ INSTMODE= 0777
|
||||
|
||||
|
||||
BINS = testlib_sharedlibc
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c sharedmemory.c
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
||||
|
||||
|
@ -124,7 +124,7 @@ const int nDacs=NDAC;
|
||||
const int nAdcs=NADC;
|
||||
#endif
|
||||
|
||||
|
||||
extern enum detectorType myDetectorType;
|
||||
|
||||
|
||||
int mapCSP0(void) {
|
||||
@ -1140,11 +1140,10 @@ u_int32_t testRAM(void) {
|
||||
|
||||
|
||||
int getNModBoard() {
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
if(myDetectorType == JUNGFRAU)
|
||||
return 1;
|
||||
#else
|
||||
else
|
||||
return 32;//nModX;
|
||||
#endif
|
||||
}
|
||||
|
||||
int setNMod(int n) {
|
||||
@ -1343,14 +1342,15 @@ int64_t getFramesFromStart(){
|
||||
|
||||
|
||||
ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
|
||||
if(myDetectorType == JUNGFRAU)
|
||||
cprintf(RED,"ROI Not implemented for Jungfrau yet\n");
|
||||
return NULL;
|
||||
#else
|
||||
return NULL;
|
||||
|
||||
|
||||
ROI retval[MAX_ROIS];
|
||||
int i, ich;
|
||||
adcDisableMask=0xfffffffff; /**has one f too many?, dhanya*/
|
||||
adcDisableMask=0xfffffffff; /*warning: integer constant is too large for ‘long’ type,warning: large integer implicitly truncated to unsigned type*/
|
||||
|
||||
printf("Setting ROI\n");
|
||||
if (nroi>=0) {
|
||||
@ -1403,15 +1403,13 @@ ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
|
||||
}
|
||||
}
|
||||
getDynamicRange();
|
||||
return retval;
|
||||
#endif
|
||||
return retval;/*warning: function returns address of local variable*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
int loadImage(int index, short int ImageVals[]){
|
||||
|
||||
index;
|
||||
Imagevals;
|
||||
printf("loadImage Not implemented yet\n");
|
||||
|
||||
/*
|
||||
@ -1700,7 +1698,7 @@ ip.ip_destip = destip;
|
||||
|
||||
|
||||
count=sizeof(ip);
|
||||
addr=&(ip);
|
||||
addr=&(ip); /* warning: assignment from incompatible pointer type */
|
||||
while( count > 1 ) {
|
||||
sum += *addr++;
|
||||
count -= 2;
|
||||
@ -2348,15 +2346,15 @@ int setDynamicRange(int dr) {
|
||||
|
||||
|
||||
int getDynamicRange() {
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
dynamicRange=16;
|
||||
return dynamicRange;
|
||||
#else
|
||||
return dynamicRange;
|
||||
}
|
||||
|
||||
nSamples=bus_r(NSAMPLES_REG);
|
||||
getChannels();
|
||||
dataBytes=nModX*NCHIP*getChannels()*2;
|
||||
return dynamicRange*bus_r(NSAMPLES_REG);//nSamples;
|
||||
#endif
|
||||
}
|
||||
|
||||
int testBus() {
|
||||
@ -2866,7 +2864,7 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
|
||||
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
|
||||
#endif
|
||||
|
||||
memcpy(CounterVals,ptr,dataBytes);
|
||||
memcpy(CounterVals,ptr,dataBytes); /*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*/
|
||||
#ifdef VERBOSE
|
||||
int i;
|
||||
printf("Copied counter memory block with size of %d bytes..\n",dataBytes);
|
||||
@ -2936,7 +2934,7 @@ int resetCounterBlock(int startACQ){
|
||||
#endif
|
||||
|
||||
|
||||
memcpy(counterVals,ptr,dataBytes);
|
||||
memcpy(counterVals,ptr,dataBytes);/*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*/
|
||||
#ifdef VERBOSE
|
||||
int i;
|
||||
printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals));
|
||||
@ -3128,7 +3126,7 @@ uint64_t writePatternWord(int addr, uint64_t word) {
|
||||
return readPatternWord(addr);
|
||||
}
|
||||
uint64_t writePatternIOControl(uint64_t word) {
|
||||
if (word!=0xffffffffffffffff) {
|
||||
if (word!=0xffffffffffffffff) { /*warning: integer constant is too large for ‘long’ type*/
|
||||
// printf("%llx %llx %lld",get64BitReg(PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB),word);
|
||||
set64BitReg(word,PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB);
|
||||
// printf("************ write IOCTRL (%x)\n",PATTERN_IOCTRL_REG_MSB);
|
||||
@ -3137,7 +3135,7 @@ uint64_t writePatternIOControl(uint64_t word) {
|
||||
|
||||
}
|
||||
uint64_t writePatternClkControl(uint64_t word) {
|
||||
if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);
|
||||
if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);/*warning: integer constant is too large for ‘long’ type*/
|
||||
return get64BitReg(PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);
|
||||
|
||||
}
|
||||
@ -3282,7 +3280,7 @@ void initDac(int dacnum) {
|
||||
|
||||
|
||||
printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx);
|
||||
codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0));
|
||||
codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0)); /*warning: suggest parentheses around + or - inside shift*/
|
||||
|
||||
valw=0xffff; bus_w(offw,(valw)); // start point
|
||||
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
|
||||
|
Binary file not shown.
@ -43,6 +43,7 @@ int *detectorAdcs=NULL;
|
||||
|
||||
ROI rois[MAX_ROIS];
|
||||
int nROI=0;
|
||||
extern enum detectorType myDetectorType;
|
||||
|
||||
|
||||
int initDetector() {
|
||||
@ -58,30 +59,33 @@ int initDetector() {
|
||||
|
||||
detectorModules=malloc(n*sizeof(sls_detector_module));
|
||||
detectorDacs=malloc(n*NDAC*sizeof(int));
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
detectorChips=malloc(n*NCHIP*sizeof(int));
|
||||
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||
detectorAdcs=malloc(n*NADC*sizeof(int));
|
||||
#endif
|
||||
detectorChips=NULL;
|
||||
detectorChans=NULL;
|
||||
detectorAdcs=NULL;
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
detectorChips=malloc(n*NCHIP*sizeof(int));
|
||||
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n));
|
||||
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC));
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
|
||||
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
|
||||
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC));
|
||||
#endif
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
|
||||
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for (imod=0; imod<n; imod++) {
|
||||
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
|
||||
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
|
||||
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
|
||||
#endif
|
||||
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
|
||||
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
|
||||
}
|
||||
(detectorModules+imod)->ndac=NDAC;
|
||||
(detectorModules+imod)->nadc=NADC;
|
||||
(detectorModules+imod)->nchip=NCHIP;
|
||||
@ -217,28 +221,27 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||
|
||||
// printf("copying gain and offset %f %f to %f %f\n",srcMod->gain,srcMod->offset,destMod->gain,destMod->offset);
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
|
||||
if (*((srcMod->chipregs)+ichip)>=0)
|
||||
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
|
||||
if (*((srcMod->chipregs)+ichip)>=0)
|
||||
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
|
||||
}
|
||||
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
|
||||
if (*((srcMod->chanregs)+ichan)>=0)
|
||||
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
|
||||
}
|
||||
}
|
||||
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
|
||||
if (*((srcMod->chanregs)+ichan)>=0)
|
||||
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (idac=0; idac<(srcMod->ndac); idac++) {
|
||||
if (*((srcMod->dacs)+idac)>=0)
|
||||
*((destMod->dacs)+idac)=*((srcMod->dacs)+idac);
|
||||
}
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
for (iadc=0; iadc<(srcMod->nadc); iadc++) {
|
||||
if (*((srcMod->adcs)+iadc)>=0)
|
||||
*((destMod->adcs)+iadc)=*((srcMod->adcs)+iadc);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -900,9 +903,9 @@ int setSettings(int i, int imod) {
|
||||
}
|
||||
|
||||
thisSettings=isett;
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
printf("detector settings are %d\n",thisSettings);
|
||||
#endif
|
||||
//#endif
|
||||
return thisSettings;
|
||||
}
|
||||
|
||||
|
@ -19,21 +19,21 @@
|
||||
#define FPGA_INIT_PAT 0x60008
|
||||
#define FPGA_INIT_ADDR 0xb0000000
|
||||
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
#define POWER_ON_REG 0x5e<<11
|
||||
#define ADCREG1 0x08
|
||||
#define ADCREG2 0x14
|
||||
#define ADCREG3 0x4
|
||||
#define ADCREG4 0x5
|
||||
#define ADCREG_VREFS 0x18
|
||||
#define ADC_PIPELINE_REG 0x42<<11 // adc_offset_reg
|
||||
#define DBIT_PIPELINE_REG 0x59<<11
|
||||
#define MEM_MACHINE_FIFOS_REG 0x4f<<11
|
||||
#define CONFGAIN_REG 0x5d<<11 /** was actually GAIN_REG which seems to be set to 0 later in this file*/
|
||||
#endif
|
||||
//#ifdef JUNGFRAU_DHANYA
|
||||
#define POWER_ON_REG 0x5e<<11
|
||||
#define ADCREG1 8 //same as PLL_BANDWIDTH_REG
|
||||
#define ADCREG2 20 //0x14
|
||||
#define ADCREG3 4 //same as PLL_M_COUNTER_REG
|
||||
#define ADCREG4 5 //same as PLL_C_COUNTER_REG
|
||||
#define ADCREG_VREFS 24 //0x18
|
||||
#define DBIT_PIPELINE_REG 89<<11 //0x59 same PATTERN_N_LOOP2_REG
|
||||
#define MEM_MACHINE_FIFOS_REG 79<<11 //0x4f same as CONTROL_REG
|
||||
#define CONFGAIN_REG 93<<11 //0x5d same as DAQ_REG
|
||||
#define ADC_PIPELINE_REG 66<<11 //0x42 same as ADC_OFFSET_REG
|
||||
//#endif
|
||||
|
||||
|
||||
#define ADC_INVERSION_REG 67<<11 /** picked up from after ADC_OFFSET_REG*/
|
||||
#define ADC_OFFSET_REG 66<<11 //same as ADC_PIPELINE_REG
|
||||
#define ADC_INVERSION_REG 67<<11
|
||||
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@
|
||||
//#define ADC_SYNC_REG 66<<11//0x19<<11
|
||||
//#define HV_REG 67<<11//0x20<<11
|
||||
|
||||
#define ADC_OFFSET_REG 66<<11
|
||||
|
||||
|
||||
|
||||
//#define MUTIME_REG 0x1a<<11
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "server_defs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "trimming_funcs.h"
|
||||
#include "registers_m.h"
|
||||
#include "gitInfoMoench.h"
|
||||
|
||||
@ -59,18 +58,15 @@ int adcvpp=0x4;
|
||||
int init_detector(int b, int checkType) {
|
||||
|
||||
int i;
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
int retvalsize,ret;
|
||||
#endif
|
||||
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
//print version
|
||||
printf("v: 0x%x\n",bus_r(FPGA_VERSION_REG));
|
||||
printf("fp: 0x%x\n",bus_r(FIX_PATT_REG));
|
||||
|
||||
//checktype
|
||||
if (checkType) {
|
||||
printf("Bus test... (checktype is %d; b is %d)",checkType,b );
|
||||
for (i=0; i<1000000; i++) {
|
||||
@ -82,7 +78,9 @@ int init_detector(int b, int checkType) {
|
||||
printf("Finished\n");
|
||||
}else
|
||||
printf("(checktype is %d; b is %d)",checkType,b );
|
||||
//confirm if it is really moench
|
||||
|
||||
|
||||
//confirm the detector type
|
||||
switch ((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) {
|
||||
case MOENCH03_MODULE_ID:
|
||||
myDetectorType=MOENCH;
|
||||
@ -102,18 +100,14 @@ int init_detector(int b, int checkType) {
|
||||
default:
|
||||
myDetectorType=GENERIC;
|
||||
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
printf("Detector type is %d\n", myDetectorType);
|
||||
|
||||
|
||||
// return OK;
|
||||
|
||||
//control server only--
|
||||
if (b) {
|
||||
|
||||
|
||||
resetPLL();
|
||||
bus_w16(CONTROL_REG, SYNC_RESET);
|
||||
bus_w16(CONTROL_REG, 0);
|
||||
@ -122,29 +116,24 @@ int init_detector(int b, int checkType) {
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
initDetector();
|
||||
#endif
|
||||
if(myDetectorType == JUNGFRAU)
|
||||
initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/
|
||||
printf("Initializing Detector\n");
|
||||
//bus_w16(CONTROL_REG, SYNC_RESET); // reset registers
|
||||
#endif
|
||||
|
||||
|
||||
// testFpga();
|
||||
// testRAM();
|
||||
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
|
||||
//moench specific
|
||||
|
||||
// setPhaseShiftOnce(); //firmware.h
|
||||
|
||||
prepareADC(); // server_funcs
|
||||
// setPhaseShiftOnce();
|
||||
/*some registers set, which is in common with jungfrau, please check */
|
||||
prepareADC();
|
||||
//setADC(-1); //already does setdaqreg and clean fifo
|
||||
// setSettings(GET_SETTINGS,-1);
|
||||
|
||||
/*some registers set, which is in common with jungfrau, please check */
|
||||
initDac(0); initDac(8); //initializes the two dacs
|
||||
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
|
||||
if(myDetectorType==JUNGFRAU){
|
||||
//set dacs
|
||||
int retval = -1;
|
||||
@ -186,7 +175,7 @@ int init_detector(int b, int checkType) {
|
||||
bus_w(ADC_INVERSION_REG,0x453b2a9c);
|
||||
|
||||
//set adc_pipeline
|
||||
bus_w(ADC_PIPELINE_REG,0x20);
|
||||
bus_w(ADC_PIPELINE_REG,0x20); //same as ADC_OFFSET_REG
|
||||
|
||||
//set dbit_pipeline
|
||||
bus_w(DBIT_PIPELINE_REG,0x100e);
|
||||
@ -202,13 +191,10 @@ int init_detector(int b, int checkType) {
|
||||
|
||||
//set default setting
|
||||
setSettings(DYNAMICGAIN,-1);
|
||||
cprintf(BLUE,"set to dynamic gain\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//Initialization
|
||||
//Initialization of acquistion parameters
|
||||
setFrames(-1);
|
||||
setTrains(-1);
|
||||
setExposureTime(-1);
|
||||
@ -220,20 +206,23 @@ int init_detector(int b, int checkType) {
|
||||
setMaster(GET_MASTER);
|
||||
setSynchronization(GET_SYNCHRONIZATION_MODE);
|
||||
startReceiver(0); //firmware
|
||||
}
|
||||
}//end of control server only--
|
||||
else printf("\n\n");
|
||||
|
||||
|
||||
//common for both control and stop server
|
||||
strcpy(mess,"dummy message");
|
||||
strcpy(lastClientIP,"none");
|
||||
strcpy(thisClientIP,"none1");
|
||||
lockStatus=0;
|
||||
// getDynamicRange();
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
setROI(-1,NULL,&retvalsize,&ret);
|
||||
allocateRAM(); //dhanya - already being done.. and all this should be inside if (b){} ??
|
||||
#endif
|
||||
|
||||
|
||||
/* both these functions setROI and allocateRAM should go into the control server part. */
|
||||
if(myDetectorType!=JUNGFRAU){
|
||||
int retvalsize,ret;
|
||||
setROI(-1,NULL,&retvalsize,&ret);
|
||||
allocateRAM();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -1505,50 +1494,54 @@ int get_chip(int file_des) {
|
||||
|
||||
}
|
||||
int set_module(int file_des) {
|
||||
sls_detector_module myModule;
|
||||
int *myDac=malloc(NDAC*sizeof(int));
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
int *myChip=malloc(NCHIP*sizeof(int));
|
||||
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
int *myAdc=malloc(NADC*sizeof(int));
|
||||
#endif
|
||||
|
||||
int retval, n;
|
||||
int ret=OK;
|
||||
int dr;// ow;
|
||||
int dr;
|
||||
sls_detector_module myModule;
|
||||
int *myDac=malloc(NDAC*sizeof(int));
|
||||
int *myAdc=malloc(NADC*sizeof(int));
|
||||
int *myChip=NULL;
|
||||
int *myChan=NULL;
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
myChip=malloc(NCHIP*sizeof(int));
|
||||
myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
}
|
||||
|
||||
dr=setDynamicRange(-1);
|
||||
dr=setDynamicRange(-1); /* move this down to after initialization?*/
|
||||
|
||||
//initialize myModule values
|
||||
if (myDac)
|
||||
myModule.dacs=myDac;
|
||||
else {
|
||||
sprintf(mess,"could not allocate dacs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
#else
|
||||
myModule.adcs=NULL;
|
||||
|
||||
myModule.chipregs=NULL;
|
||||
myModule.chanregs=NULL;
|
||||
#endif
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
myModule.ndac=NDAC;
|
||||
myModule.nchip=NCHIP;
|
||||
@ -1558,7 +1551,11 @@ int set_module(int file_des) {
|
||||
#ifdef VERBOSE
|
||||
printf("Setting module\n");
|
||||
#endif
|
||||
ret=receiveModule(file_des, &myModule);
|
||||
|
||||
if(myDetectorType != JUNGFRAU)
|
||||
ret=receiveModuleGeneral(file_des, &myModule, 1); //1 is to receive everything
|
||||
else
|
||||
ret=receiveModuleGeneral(file_des, &myModule, 0); //0 is to receive partially (without trimbits etc.)
|
||||
|
||||
if (ret>=0)
|
||||
ret=OK;
|
||||
@ -1609,17 +1606,12 @@ int set_module(int file_des) {
|
||||
}
|
||||
|
||||
free(myDac);
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
free(myChip);
|
||||
free(myChan);
|
||||
free(myAdc);
|
||||
#endif
|
||||
if(myAdc != NULL) free(myAdc);
|
||||
if(myChip != NULL) free(myChip);
|
||||
if(myChan != NULL) free(myChan);
|
||||
|
||||
|
||||
|
||||
|
||||
// setDynamicRange(dr); always 16 commented out
|
||||
printf("freed\n");
|
||||
//setDynamicRange(dr); always 16 commented out
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1629,23 +1621,23 @@ printf("freed\n");
|
||||
|
||||
int get_module(int file_des) {
|
||||
|
||||
|
||||
int ret=OK;
|
||||
|
||||
|
||||
int arg;
|
||||
int imod;
|
||||
int n;
|
||||
|
||||
|
||||
|
||||
sls_detector_module myModule;
|
||||
int *myDac=malloc(NDAC*sizeof(int));
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
int *myChip=malloc(NCHIP*sizeof(int));
|
||||
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
int *myAdc=malloc(NADC*sizeof(int));
|
||||
#endif
|
||||
int *myChip=NULL;
|
||||
int *myChan=NULL;
|
||||
int *myAdc=NULL;
|
||||
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
myChip=malloc(NCHIP*sizeof(int));
|
||||
myChan=malloc(NCHIP*NCHAN*sizeof(int));
|
||||
myAdc=malloc(NADC*sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
if (myDac)
|
||||
myModule.dacs=myDac;
|
||||
@ -1654,30 +1646,32 @@ int get_module(int file_des) {
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
#else
|
||||
|
||||
myModule.adcs=NULL;
|
||||
myModule.chipregs=NULL;
|
||||
myModule.chanregs=NULL;
|
||||
#endif
|
||||
/*not required for jungfrau. so save memory*/
|
||||
if(myDetectorType != JUNGFRAU){
|
||||
if (myAdc)
|
||||
myModule.adcs=myAdc;
|
||||
else {
|
||||
sprintf(mess,"could not allocate adcs\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChip)
|
||||
myModule.chipregs=myChip;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chips\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
if (myChan)
|
||||
myModule.chanregs=myChan;
|
||||
else {
|
||||
sprintf(mess,"could not allocate chans\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
myModule.ndac=NDAC;
|
||||
myModule.nchip=NCHIP;
|
||||
myModule.nchan=NCHAN*NCHIP;
|
||||
@ -1685,8 +1679,6 @@ int get_module(int file_des) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
@ -1717,17 +1709,19 @@ int get_module(int file_des) {
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret!=FAIL) {
|
||||
/* send return argument */
|
||||
ret=sendModule(file_des, &myModule);
|
||||
if(myDetectorType != JUNGFRAU)
|
||||
ret=sendModuleGeneral(file_des, &myModule,1); //1 is to send everything
|
||||
else
|
||||
ret=sendModuleGeneral(file_des, &myModule,0); //0 is to send partially (without trimbits etc.)
|
||||
} else {
|
||||
n += sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
|
||||
free(myDac);
|
||||
#ifndef JUNGFRAU_DHANYA
|
||||
free(myChip);
|
||||
free(myChan);
|
||||
free(myAdc);
|
||||
#endif
|
||||
if(myChip != NULL) free(myChip);
|
||||
if(myChan != NULL) free(myChan);
|
||||
if(myAdc != NULL) free(myAdc);
|
||||
|
||||
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
@ -1951,7 +1945,7 @@ int get_run_status(int file_des) {
|
||||
|
||||
retval= runState();
|
||||
printf("\n\nSTATUS=%08x\n",retval);
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
if(!(retval&RUN_BUSY_BIT)){
|
||||
|
||||
if((retval&READMACHINE_BUSY_BIT) ){
|
||||
@ -1979,7 +1973,7 @@ int get_run_status(int file_des) {
|
||||
s=RUNNING;
|
||||
}
|
||||
}
|
||||
#else
|
||||
}else{
|
||||
//error
|
||||
if(retval&SOME_FIFO_FULL_BIT){
|
||||
printf("-----------------------------------ERROR--------------------------------------x%0x\n",retval);
|
||||
@ -2025,7 +2019,7 @@ int get_run_status(int file_des) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (ret!=OK) {
|
||||
@ -2049,10 +2043,8 @@ int get_run_status(int file_des) {
|
||||
|
||||
int read_frame(int file_des) {
|
||||
|
||||
|
||||
u_int16_t* p=NULL;
|
||||
|
||||
|
||||
if (differentClients==1 && lockStatus==1) {
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
@ -2066,28 +2058,6 @@ int read_frame(int file_des) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef JUNGFRAU_DHANYA1
|
||||
while(runBusy()){
|
||||
usleep(0);
|
||||
if (getFrames() <= -1) {
|
||||
printf("no frames left, but still busy\n");
|
||||
}
|
||||
}
|
||||
if (getFrames() > -1) {
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()));
|
||||
printf("Warning: %s\n",mess);
|
||||
}else{
|
||||
dataret = FINISHED;
|
||||
sprintf(mess,"acquisition successfully finished\n");
|
||||
printf("%s\n",mess);
|
||||
}
|
||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
//dataret is never ok to send databytes for jungfrau (not reading from fifo)
|
||||
#else
|
||||
|
||||
p=fifo_read_frame();
|
||||
if (p) {
|
||||
nframes++;
|
||||
@ -2120,7 +2090,7 @@ int read_frame(int file_des) {
|
||||
sendDataOnly(file_des,mess,sizeof(mess));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return dataret;
|
||||
@ -2441,62 +2411,50 @@ int set_roi(int file_des) {
|
||||
ROI arg[MAX_ROIS];
|
||||
ROI* retval=0;
|
||||
strcpy(mess,"Could not set/get roi\n");
|
||||
|
||||
|
||||
// u_int32_t disable_reg=0;
|
||||
|
||||
|
||||
n = receiveDataOnly(file_des,&nroi,sizeof(nroi));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Not applicable/implemented for this detector\n");
|
||||
printf("Error:Set ROI-%s",mess);
|
||||
#else
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Not applicable/implemented for this detector\n");
|
||||
printf("Error:Set ROI-%s",mess);
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
if(nroi>=0){
|
||||
n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI));
|
||||
if (n != (nroi*sizeof(ROI))) {
|
||||
sprintf(mess,"Received wrong number of bytes for ROI\n");
|
||||
if(nroi>=0){
|
||||
n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI));
|
||||
if (n != (nroi*sizeof(ROI))) {
|
||||
sprintf(mess,"Received wrong number of bytes for ROI\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
printf("Setting ROI to:");
|
||||
for( i=0;i<nroi;i++)
|
||||
printf("%d\t%d\t%d\t%d\n",arg[i].xmin,arg[i].xmax,arg[i].ymin,arg[i].ymax);
|
||||
printf("Error: Function 41 or Setting ROI is not yet implemented in Moench!\n");
|
||||
|
||||
}
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Detector locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
//#ifdef VERBOSE
|
||||
|
||||
printf("Setting ROI to:");
|
||||
for( i=0;i<nroi;i++)
|
||||
printf("%d\t%d\t%d\t%d\n",arg[i].xmin,arg[i].xmax,arg[i].ymin,arg[i].ymax);
|
||||
|
||||
|
||||
|
||||
//
|
||||
printf("Error: Function 41 or Setting ROI is not yet implemented in Moench!\n");
|
||||
//#endif
|
||||
}
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (lockStatus==1 && differentClients==1){//necessary???
|
||||
sprintf(mess,"Detector locked by %s\n", lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else{
|
||||
retval=setROI(nroi,arg,&retvalsize,&ret);
|
||||
|
||||
if (ret==FAIL){
|
||||
printf("mess:%s\n",mess);
|
||||
sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize);
|
||||
else{
|
||||
retval=setROI(nroi,arg,&retvalsize,&ret);
|
||||
if (ret==FAIL){
|
||||
printf("mess:%s\n",mess);
|
||||
sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && differentClients){
|
||||
printf("Force update\n");
|
||||
|
@ -1,765 +0,0 @@
|
||||
#ifndef PICASSOD
|
||||
#include "server_defs.h"
|
||||
#else
|
||||
#include "picasso_defs.h"
|
||||
#endif
|
||||
#include "trimming_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
extern int nModX;
|
||||
//extern int *values;
|
||||
|
||||
extern const int nChans;
|
||||
extern const int nChips;
|
||||
extern const int nDacs;
|
||||
extern const int nAdcs;
|
||||
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int im)
|
||||
{
|
||||
|
||||
int retval=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming with fixed settings\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
if (par2<=0)
|
||||
retval=trim_with_level(countlim, im);
|
||||
else
|
||||
retval=trim_with_median(countlim,im);
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int trim_with_noise(int countlim, int nsigma, int im)
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming using noise\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
/* threshold scan */
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("trimming with noise.....\n");
|
||||
#endif
|
||||
retval2=trim_with_level(countlim, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int trim_with_beam(int countlim, int nsigma, int im) //rpc
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
printf("Trimming using beam\n");
|
||||
//return OK;
|
||||
#ifdef VIRTUAL
|
||||
printf("Trimming using beam\n");
|
||||
return OK;
|
||||
#endif
|
||||
/* threshold scan */
|
||||
#ifdef DEBUGOUT
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
|
||||
retval2=trim_with_median(TRIM_DR, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int trim_improve(int maxit, int par2, int im) //rpc
|
||||
{
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Improve the trimming\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
|
||||
if (par2!=0 && im==ALLMOD)
|
||||
retval1=choose_vthresh();
|
||||
|
||||
retval2=trim_with_median(2*maxit+1, im);
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int calcthr_from_vcal(int vcal) {
|
||||
int thrmin;
|
||||
//thrmin=140+3*vcal/5;
|
||||
thrmin=180+3*vcal/5;
|
||||
return thrmin;
|
||||
}
|
||||
|
||||
int calccal_from_vthr(int vthr) {
|
||||
int vcal;
|
||||
vcal=5*(vthr-140)/3;
|
||||
return vcal;
|
||||
}
|
||||
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
int retval=OK;
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
cprintf(RED,"choose_vthresh_and_vtrim Not implemented for JungFrau\n");//did not want to fix warnings
|
||||
#else
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int modma, modmi, nm;
|
||||
int thr, thrstep=5, nthr=31;
|
||||
|
||||
int *fifodata;
|
||||
|
||||
double vthreshmean, vthreshSTDev;
|
||||
int *thrmi, *thrma;
|
||||
double c;
|
||||
double b=BVTRIM;
|
||||
double a=AVTRIM;
|
||||
int *trim;
|
||||
int ich, imod, ichan;
|
||||
int nvalid=0;
|
||||
u_int32_t *scan;
|
||||
int ithr;
|
||||
sls_detector_channel myChan;
|
||||
|
||||
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
trim=malloc(sizeof(int)*nChans*nChips*nModX);
|
||||
thrmi=malloc(sizeof(int)*nModX);
|
||||
thrma=malloc(sizeof(int)*nModX);
|
||||
|
||||
|
||||
for (ich=0; ich<nChans*nChips*nm; ich++)
|
||||
trim[ich]=-1;
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
counterClear(im);
|
||||
clearSSregister(im);
|
||||
usleep(500);
|
||||
*/
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE;
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
|
||||
for (ithr=0; ithr<nthr; ithr++) {
|
||||
fifoReset();
|
||||
/* scanning threshold */
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//commented out by dhanya thr=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if (ithr==0) {
|
||||
thrmi[imod]=thr;
|
||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
} else
|
||||
;//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
|
||||
}
|
||||
|
||||
/* setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChips*nChans+ichan;
|
||||
if (scan[ich]>countlim && trim[ich]==-1) {
|
||||
//commented out by dhanya trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
#ifdef VERBOSE
|
||||
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
#endif
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else {
|
||||
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
vthreshmean=0;
|
||||
vthreshSTDev=0;
|
||||
nvalid=0;
|
||||
//commented out by dhanya thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChans*nChips+ichan;
|
||||
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
|
||||
vthreshmean=vthreshmean+trim[ich];
|
||||
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
|
||||
nvalid++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvalid>0) {
|
||||
vthreshmean=vthreshmean/nvalid;
|
||||
//commented out by dhanya vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean);
|
||||
} else {
|
||||
vthreshmean=thrmi[imod];
|
||||
vthreshSTDev=nthr*thrstep;
|
||||
printf("No valid channel for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
|
||||
#endif
|
||||
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
|
||||
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
|
||||
if (thr<0 || thr>(DAC_DR-1)) {
|
||||
thr=thrmi[imod]/2;
|
||||
printf("Can't find correct threshold for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
#ifdef VERBOSE
|
||||
printf("vthresh=%d \n",thr);
|
||||
#endif
|
||||
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
|
||||
//commented out by dhanya thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a));
|
||||
if (thr<500 || thr>(DAC_DR-1)) {
|
||||
thr=750;
|
||||
printf("Can't find correct trimbit size for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
//commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("vtrim=%d \n",thr);
|
||||
#endif
|
||||
|
||||
}
|
||||
free(trim);
|
||||
free(thrmi);
|
||||
free(thrma);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_level(int countlim, int im) {
|
||||
int retval=OK;
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
cprintf(RED,"trim_with_level Not implemented for JungFrau\n"); //did not want to fix warnings
|
||||
#else
|
||||
int ich, itrim, ichan, ichip, imod;
|
||||
u_int32_t *scan;
|
||||
int *inttrim;
|
||||
int modma, modmi, nm;
|
||||
int *fifodata;
|
||||
sls_detector_channel myChan;
|
||||
printf("trimming module number %d", im);
|
||||
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
|
||||
printf("countlim=%d\n",countlim);
|
||||
for (ich=0; ich<nChans*nChips*nModX; ich++)
|
||||
inttrim[ich]=-1;
|
||||
|
||||
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
|
||||
fifoReset();
|
||||
printf("Trimbit %d\n",itrim);
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(itrim,0,0,1,0,0,ALLMOD);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
||||
ich=ichan+imod*nChans*nChips;
|
||||
if (inttrim[ich]==-1) {
|
||||
if (scan[ich]>countlim){
|
||||
inttrim[ich]=itrim;
|
||||
if (scan[ich]>2*countlim && itrim>0) {
|
||||
//if (scan[ich]>2*countlim || itrim==0) {
|
||||
inttrim[ich]=itrim-1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else
|
||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
clearCSregister(imod);
|
||||
firstChip(im);
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
clearSSregister(imod);
|
||||
for (ichan=0; ichan<nChans; ichan++) {
|
||||
nextStrip(imod);
|
||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
||||
if (*(inttrim+ich)==-1) {
|
||||
*(inttrim+ich)=TRIM_DR;
|
||||
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
||||
retval=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
// else
|
||||
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
||||
#endif
|
||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
||||
}
|
||||
nextChip(imod);
|
||||
}
|
||||
}
|
||||
free(inttrim);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
||||
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
|
||||
|
||||
|
||||
int kth_smallest(int *a, int n, int k)
|
||||
{
|
||||
register int i,j,l,m ;
|
||||
register double x ;
|
||||
|
||||
l=0 ; m=n-1 ;
|
||||
while (l<m) {
|
||||
x=a[k] ;
|
||||
i=l ;
|
||||
j=m ;
|
||||
do {
|
||||
while (a[i]<x) i++ ;
|
||||
while (x<a[j]) j-- ;
|
||||
if (i<=j) {
|
||||
ELEM_SWAP(a[i],a[j]) ;
|
||||
i++ ; j-- ;
|
||||
}
|
||||
} while (i<=j) ;
|
||||
if (j<k) l=i ;
|
||||
if (k<i) m=j ;
|
||||
}
|
||||
return a[k] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ave(int *a, int n)
|
||||
{
|
||||
int av=0,i;
|
||||
for (i=0; i<n; i++)
|
||||
av=av+((double)*(a+i))/((double)n);
|
||||
return av;
|
||||
}
|
||||
|
||||
|
||||
int choose_vthresh() {
|
||||
|
||||
int retval=OK;
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
cprintf(RED,"choose_vthresh Not implemented for JungFrau\n"); //did not want to fix warnings
|
||||
#else
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], med1[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int maxiterations=10;
|
||||
int vthreshmean=0;
|
||||
int vthresh;
|
||||
int im=ALLMOD;
|
||||
int modma, modmi, nm;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
|
||||
|
||||
setDynamicRange(32);
|
||||
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
//printf(".");
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//
|
||||
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
//commented out by dhanya vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
||||
olddiff[imod]=0xffffff;
|
||||
direction[imod]=0;
|
||||
printf("Median of module %d=%d\n",imod,med[imod]);
|
||||
}
|
||||
vthreshmean=vthreshmean/nm;
|
||||
//media=median(scan,nChans*nChips*nModX);
|
||||
//printf("Median overall=%d\n",media);
|
||||
media=median(med1+modmi,nm);
|
||||
printf("Median of modules=%d\n",media);
|
||||
free(scan);
|
||||
free(scan1);
|
||||
|
||||
|
||||
while(change_flag && iteration<maxiterations) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
change_flag=0;
|
||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
||||
for (ichan=modmi; ichan<modma; ichan++) {
|
||||
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
media=median(med1+modmi,nm);
|
||||
|
||||
diff=med[ichan]-media;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
direction[ichan]=1;
|
||||
else
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
//commented out by dhanya vthresh=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
vthresh=vthresh-direction[ichan];
|
||||
if (vthresh>(DAC_DR-1)) {
|
||||
vthresh=(DAC_DR-1);
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (vthresh<0) {
|
||||
vthresh=0;
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
vthresh=vthresh+direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
//commented out by dhanya initDACbyIndex(VTHRESH,vthresh, ichan);
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_median(int stop, int im) {
|
||||
|
||||
|
||||
int retval=OK;
|
||||
#ifdef JUNGFRAU_DHANYA
|
||||
cprintf(RED,"trim_with_median Not implemented for JungFrau\n"); //did not want to fix warnings
|
||||
#else
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
u_int32_t *scan, *scan1;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int me[nModX], me1[nModX];
|
||||
int modma, modmi, nm;
|
||||
int trim;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
olddiff=malloc(4*nModX*nChips*nChans);
|
||||
direction=malloc(4*nModX*nChips*nChans);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0x0fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
/********
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
scan=decode_data(fifo_read_event());
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
free(scan);
|
||||
**************/
|
||||
while(change_flag && iteration<stop) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event(0);
|
||||
scan=decode_data(fifodata);
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
me1[imod]=me[imod];
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me1,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
selChip(ichip,imod);
|
||||
clearSSregister(imod);
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-me[imod];
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
} else {
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
}
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
if (trim>TRIM_DR) {
|
||||
trim=63;
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (trim<0) {
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
trim=0;
|
||||
retval=FAIL;
|
||||
}
|
||||
initChannel(trim,0,0,1,0,0,imod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
free(olddiff);
|
||||
free(direction);
|
||||
#endif
|
||||
#endif
|
||||
return retval;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#ifndef TRIMMING_FUNCS_H
|
||||
#define TRIMMING_FUNCS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int imod);
|
||||
int trim_with_noise(int countlim, int nsigma, int imod);
|
||||
int trim_with_beam(int countlim, int nsigma, int imod);
|
||||
int trim_improve(int maxit, int par2, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
|
||||
|
||||
int choose_vthresh();
|
||||
int trim_with_level(int countlim, int imod);
|
||||
int trim_with_median(int stop, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
|
||||
#endif
|
@ -1083,18 +1083,18 @@ int slsDetector::sendModule(sls_detector_module *myMod) {
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->nadc),sizeof(myMod->nadc));
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->reg),sizeof(myMod->reg));
|
||||
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(myMod->ndac));
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
}
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->gain),sizeof(myMod->gain));
|
||||
ts+=controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset));
|
||||
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||
}
|
||||
@ -1151,8 +1151,9 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
|
||||
ts+=controlSocket->ReceiveDataOnly(&(myMod->nadc),sizeof(myMod->nadc));
|
||||
ts+=controlSocket->ReceiveDataOnly(&(myMod->reg),sizeof(myMod->reg));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(myMod->ndac));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip));
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan));
|
||||
}
|
||||
@ -1172,12 +1173,12 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received dacs " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl;
|
||||
#endif
|
||||
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user