sorted out problem with CPU read out

This commit is contained in:
bergamaschi 2016-12-22 17:24:53 +01:00
parent 3eea80a121
commit 987aeda6fb
13 changed files with 982 additions and 1010 deletions

View File

@ -372,7 +372,8 @@ enum dacIndex {
V_POWER_C = 102, /**new chiptest board */ V_POWER_C = 102, /**new chiptest board */
V_POWER_D = 103, /**new chiptest board */ V_POWER_D = 103, /**new chiptest board */
V_POWER_IO =104, /**new chiptest board */ V_POWER_IO =104, /**new chiptest board */
V_POWER_CHIP=105 /**new chiptest board */ V_POWER_CHIP=105 ,/**new chiptest board */
V_LIMIT=106 /**new chiptest board */
}; };
/** /**

View File

@ -111,8 +111,6 @@ enum {
F_POWER_CHIP, /**< power chip */ F_POWER_CHIP, /**< power chip */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */
/* Always append functions before!!! */ /* Always append functions before!!! */
TOO_MANY_FUNCTIONS_DEFINED=128 //you should get a compilation error if there are already so many functions defined. It conflicts with sls_receiver_funcs.h TOO_MANY_FUNCTIONS_DEFINED=128 //you should get a compilation error if there are already so many functions defined. It conflicts with sls_receiver_funcs.h

View File

@ -120,23 +120,23 @@ int withGotthard = 0;
* why is this used anywhere instead of macro*/ * why is this used anywhere instead of macro*/
int nChans=NCHAN; int nChans=NCHAN;
int nChips=NCHIP; int nChips=NCHIP;
int nDacs=NDAC; //int nDacs;//=NDAC;
int nAdcs=NADC; //int nAdcs=NADC;
extern enum detectorType myDetectorType; extern enum detectorType myDetectorType;
/** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/ /** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/
extern int N_CHAN; extern int N_CHAN;
extern int N_CHIP; extern int N_CHIP;
extern int N_DAC; extern int N_DAC;
extern int N_ADC; extern int N_ADC;
extern int N_CHANS; extern int N_CHANS;
int analogEnable=1; int analogEnable=1;
int digitalEnable=0; int digitalEnable=0;
int vLimit=-100;
@ -1267,10 +1267,8 @@ u_int32_t testRAM(void) {
int getNModBoard() { int getNModBoard() {
if(myDetectorType == JUNGFRAU)
return 1; return 1;
else
return 32;//nModX;
} }
int setNMod(int n) { int setNMod(int n) {
@ -1489,7 +1487,7 @@ int setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
// ROI retval[MAX_ROIS]; // ROI retval[MAX_ROIS];
int i, ich; int i, ich;
adcDisableMask=0xfffffffff; /*warning: integer constant is too large for long type,warning: large integer implicitly truncated to unsigned type*/ adcDisableMask=0xffffffff;
printf("Setting ROI\n"); printf("Setting ROI\n");
if (nroi>=0) { if (nroi>=0) {
@ -1691,10 +1689,10 @@ int initHighVoltage(int val, int imod){
u_int32_t offw,codata; u_int32_t offw,codata;
u_int16_t valw, dacvalue; u_int16_t valw, dacvalue;
int iru,i,ddx,csdx,cdx; int i,ddx,csdx,cdx;//iru,
float alpha=0.55, fval=val; float alpha=0.55;//, fval=val;
if (val>=0) { if (val!=-1) {
if (val<60) { if (val<60) {
dacvalue=0; dacvalue=0;
@ -1705,35 +1703,44 @@ int initHighVoltage(int val, int imod){
} else { } else {
dacvalue=1.+(200.-val)/alpha; dacvalue=1.+(200.-val)/alpha;
val=200.-(dacvalue-1)*alpha; val=200.-(dacvalue-1)*alpha;
} }
printf ("****************************** setting val %d, dacval %d\n",val, dacvalue); printf ("****************************** setting val %d, dacval %d\n",val, dacvalue);
offw=DAC_REG;
if (val>=0) {
offw=DAC_REG;
ddx=8; csdx=10; cdx=9; ddx=8; csdx=10; cdx=9;
codata=((dacvalue)&0xff); codata=((dacvalue)&0xff);
valw=0xffff; bus_w(offw,(valw)); // start point valw=0xef|bus_r(offw); bus_w(offw,(valw)); // start point
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
for (i=0;i<8;i++) { for (i=0;i<8;i++) {
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=((valw&(~(0x1<<ddx)))+(((codata>>(7-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i) valw=((valw&(~(0x1<<ddx)))+(((codata>>(7-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i)
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
} }
valw=((valw&(~(0x1<<csdx)))+(0x1<<csdx));bus_w(offw,valw); //csup valw=((valw&(~(0x1<<csdx)))+(0x1<<csdx));bus_w(offw,valw); //csup
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=0xffff; bus_w(offw,(valw)); // stop point =start point of course */ valw=0xff|bus_r(offw); bus_w(offw,(valw)); // stop point =start point of course */
printf("Writing %d in HVDAC \n",dacvalue); printf("Writing %d in HVDAC \n",dacvalue);
bus_w(HV_REG,val); bus_w(HV_REG,val);
}
} else {
valw=bus_r(offw)&0xefff;
bus_w(offw,(valw));
bus_w(HV_REG,0);
}
}
@ -1766,56 +1773,56 @@ int initConfGain(int isettings,int val,int imod){
int setADC(int adc){ int setADC(int adc){
int reg,nchips,mask,nchans; /* int reg,nchips,mask,nchans; */
if(adc==-1) ROI_flag=0; /* if(adc==-1) ROI_flag=0; */
else ROI_flag=1; /* else ROI_flag=1; */
// setDAQRegister();//token timing /* // setDAQRegister();//token timing */
cleanFifo();//adc sync /* cleanFifo();//adc sync */
//with gotthard module /* //with gotthard module */
if(withGotthard){ /* if(withGotthard){ */
//set packet size /* //set packet size */
ipPacketSize= DEFAULT_IP_PACKETSIZE; /* ipPacketSize= DEFAULT_IP_PACKETSIZE; */
udpPacketSize=DEFAULT_UDP_PACKETSIZE; /* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */
//set channel mask /* //set channel mask */
nchips = GOTTHARDNCHIP; /* nchips = GOTTHARDNCHIP; */
nchans = GOTTHARDNCHAN; /* nchans = GOTTHARDNCHAN; */
mask = ACTIVE_ADC_MASK; /* mask = ACTIVE_ADC_MASK; */
} /* } */
//with moench module all adc /* //with moench module all adc */
else{/* if(adc==-1){*/ /* else{/\* if(adc==-1){*\/ */
//set packet size /* //set packet size */
ipPacketSize= DEFAULT_IP_PACKETSIZE; /* ipPacketSize= DEFAULT_IP_PACKETSIZE; */
udpPacketSize=DEFAULT_UDP_PACKETSIZE; /* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */
//set channel mask /* //set channel mask */
nchips = N_CHIP; /* nchips = N_CHIP; */
nchans = N_CHANS; /* nchans = N_CHANS; */
mask = ACTIVE_ADC_MASK; /* mask = ACTIVE_ADC_MASK; */
}/* /* }/\* */
//with moench module 1 adc -- NOT IMPLEMENTED /* //with moench module 1 adc -- NOT IMPLEMENTED */
else{ /* else{ */
ipPacketSize= ADC1_IP_PACKETSIZE; /* ipPacketSize= ADC1_IP_PACKETSIZE; */
udpPacketSize=ADC1_UDP_PACKETSIZE; /* udpPacketSize=ADC1_UDP_PACKETSIZE; */
//set channel mask /* //set channel mask */
nchips = NCHIPS_PER_ADC; /* nchips = NCHIPS_PER_ADC; */
nchans = GOTTHARDNCHAN; /* nchans = GOTTHARDNCHAN; */
mask = 1<<adc; /* mask = 1<<adc; */
}*/ /* }*\/ */
//set channel mask /* //set channel mask */
reg = (nchans*nchips)<<CHANNEL_OFFSET; /* reg = (nchans*nchips)<<CHANNEL_OFFSET; */
reg&=CHANNEL_MASK; /* reg&=CHANNEL_MASK; */
reg|=(ACTIVE_ADC_MASK & mask); /* reg|=(ACTIVE_ADC_MASK & mask); */
bus_w(CHIP_OF_INTRST_REG,reg); /* bus_w(CHIP_OF_INTRST_REG,reg); */
//#ifdef DDEBUG /* //#ifdef DDEBUG */
printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); /* printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); */
//#endif /* //#endif */
adcConfigured = adc; /* adcConfigured = adc; */
return adcConfigured; return adcConfigured;
} }
@ -1846,7 +1853,7 @@ ip.ip_destip = destip;
count=sizeof(ip); count=sizeof(ip);
addr=&(ip); /* warning: assignment from incompatible pointer type */ addr=(unsigned short*) (&(ip)); /* warning: assignment from incompatible pointer type */
while( count > 1 ) { while( count > 1 ) {
sum += *addr++; sum += *addr++;
count -= 2; count -= 2;
@ -1975,7 +1982,7 @@ volatile u_int32_t conf= bus_r(CONFIG_REG);
usleep(10000); usleep(10000);
bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT); bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT);
printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG)); printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG));
return; return OK;
} }
@ -2158,7 +2165,7 @@ u_int32_t fifo_full(void)
u_int16_t* fifo_read_event(int ns) u_int16_t* fifo_read_event(int ns)
{ {
int i=0, j, mask=1; int i=0, mask=1;//j,
volatile u_int16_t a; volatile u_int16_t a;
bus_w16(DUMMY_REG,0); bus_w16(DUMMY_REG,0);
if (ns==0) { if (ns==0) {
@ -2213,14 +2220,16 @@ u_int16_t* fifo_read_event(int ns)
} }
} }
if (digitalEnable) { if (digitalEnable) {
printf("+"); // printf("+");
bus_w16(DUMMY_REG,1<<9); // read strobe to digital fifo bus_w16(DUMMY_REG,1<<9); // read strobe to digital fifo
bus_w16(DUMMY_REG,0<<9); // read strobe to digital fifo bus_w16(DUMMY_REG,0<<9); // read strobe to digital fifo
*((u_int64_t*)now_ptr)=get64BitReg(FIFO_DIGITAL_DATA_LSB_REG,FIFO_DIGITAL_DATA_MSB_REG); *((u_int64_t*)now_ptr)=get64BitReg(FIFO_DIGITAL_DATA_LSB_REG,FIFO_DIGITAL_DATA_MSB_REG);
//bit17 is clkout
printf("%d",(*((u_int64_t*)now_ptr)>>17)&1);
now_ptr+=8; now_ptr+=8;
} }
// bus_w16(DUMMY_REG,0); // // bus_w16(DUMMY_REG,0); //
/* #ifdef TIMEDBG */ /* #ifdef TIMEDBG */
@ -2544,16 +2553,16 @@ int writeADC(int addr, int val) {
int prepareSlowADCSeq() { int prepareSlowADCSeq() {
u_int16_t vv=0x3c40; // u_int16_t vv=0x3c40;
u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1; u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1;
u_int32_t valw; u_int32_t valw;
int i, obit, ibit; int obit, ibit;
int cnv_bit=16, sdi_bit=17, sck_bit=18; int cnv_bit=16, sdi_bit=17, sck_bit=18;
int oval=0; // int oval=0;
printf("Codata is %04x\n",codata); printf("Codata is %04x\n",codata);
@ -2601,25 +2610,25 @@ int prepareSlowADCSeq() {
bus_w(ADC_WRITE_REG,(valw)); bus_w(ADC_WRITE_REG,(valw));
usleep(20); usleep(20);
return 0;
} }
int prepareSlowADC(int ichan) { int prepareSlowADC(int ichan) {
u_int16_t vv=0x3c40; // u_int16_t vv=0x3c40;
// u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1; // u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1;
u_int16_t codata=(1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel u_int16_t codata=(1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel
if (ichan<0) codata=( 1<<13) | (3<<10) | (7<7) | (1<<6) | (0<<3) | (0<<1) | 1; if (ichan<0) codata=( 1<<13) | (3<<10) | (7<7) | (1<<6) | (0<<3) | (0<<1) | 1;
u_int32_t valw; u_int32_t valw;
int i, obit, ibit; int obit, ibit;
int cnv_bit=16, sdi_bit=17, sck_bit=18; int cnv_bit=16, sdi_bit=17, sck_bit=18;
int oval=0; // int oval=0;
printf("Codata is %04x\n",codata); printf("Codata is %04x\n",codata);
@ -2667,7 +2676,7 @@ int prepareSlowADC(int ichan) {
bus_w(ADC_WRITE_REG,(valw)); bus_w(ADC_WRITE_REG,(valw));
usleep(20); usleep(20);
return 0;
} }
@ -2677,13 +2686,13 @@ int prepareSlowADC(int ichan) {
int readSlowADC(int ichan) { int readSlowADC(int ichan) {
u_int16_t vv=0x3c40; // u_int16_t vv=0x3c40;
// u_int16_t codata=( 1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel // u_int16_t codata=( 1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel
u_int32_t valw; u_int32_t valw;
int i, obit, ibit; int i, obit;
int cnv_bit=16, sdi_bit=17, sck_bit=18; int cnv_bit=16, sck_bit=18;
int oval=0; int oval=0;
@ -3114,57 +3123,57 @@ int setSynchronization(int s) {
int readCounterBlock(int startACQ, short int CounterVals[]){ int readCounterBlock(int startACQ, short int CounterVals[]){
//char *counterVals=NULL; /* //char *counterVals=NULL; */
//counterVals=realloc(counterVals,dataBytes); /* //counterVals=realloc(counterVals,dataBytes); */
u_int32_t val; /* u_int32_t val; */
volatile u_int16_t *ptr; /* volatile u_int16_t *ptr; */
u_int32_t address = COUNTER_MEMORY_REG; /* u_int32_t address = COUNTER_MEMORY_REG; */
ptr=(u_int16_t*)(CSP0BASE+address*2); /* ptr=(u_int16_t*)(CSP0BASE+address*2); */
if (runBusy()) { /* if (runBusy()) { */
if(stopStateMachine()==FAIL) /* if(stopStateMachine()==FAIL) */
return FAIL; /* return FAIL; */
//waiting for the last frame read to be done /* //waiting for the last frame read to be done */
while(runBusy()) usleep(500); /* while(runBusy()) usleep(500); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("State machine stopped\n"); /* printf("State machine stopped\n"); */
#endif /* #endif */
} /* } */
val=bus_r(MULTI_PURPOSE_REG); /* val=bus_r(MULTI_PURPOSE_REG); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); /* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
#endif /* #endif */
memcpy(CounterVals,ptr,dataBytes); /*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*/ /* memcpy(CounterVals,ptr,dataBytes); /\*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*\/ */
#ifdef VERBOSE /* #ifdef VERBOSE */
int i; /* int i; */
printf("Copied counter memory block with size of %d bytes..\n",dataBytes); /* printf("Copied counter memory block with size of %d bytes..\n",dataBytes); */
for(i=0;i<6;i++) /* for(i=0;i<6;i++) */
printf("%d: %d\t",i,CounterVals[i]); /* printf("%d: %d\t",i,CounterVals[i]); */
#endif /* #endif */
bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); /* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); /* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
#endif /* #endif */
if(startACQ==1){ /* if(startACQ==1){ */
startStateMachine(); /* startStateMachine(); */
if(runBusy()) /* if(runBusy()) */
printf("State machine RUNNING\n"); /* printf("State machine RUNNING\n"); */
else /* else */
printf("State machine IDLE\n"); /* printf("State machine IDLE\n"); */
} /* } */
/* if(sizeof(CounterVals)<=0){ /* /\* if(sizeof(CounterVals)<=0){ */
printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals)); /* printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals)); */
return FAIL; /* return FAIL; */
}*/ /* }*\/ */
return OK; return OK;
@ -3174,67 +3183,67 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
int resetCounterBlock(int startACQ){ int resetCounterBlock(int startACQ){
int ret = OK;
char *counterVals=NULL; /* char *counterVals=NULL; */
counterVals=realloc(counterVals,dataBytes); /* counterVals=realloc(counterVals,dataBytes); */
int ret = OK; /* u_int32_t val; */
u_int32_t val; /* volatile u_int16_t *ptr; */
volatile u_int16_t *ptr;
u_int32_t address = COUNTER_MEMORY_REG; /* u_int32_t address = COUNTER_MEMORY_REG; */
ptr=(u_int16_t*)(CSP0BASE+address*2); /* ptr=(u_int16_t*)(CSP0BASE+address*2); */
if (runBusy()) { /* if (runBusy()) { */
if(stopStateMachine()==FAIL) /* if(stopStateMachine()==FAIL) */
return FAIL; /* return FAIL; */
//waiting for the last frame read to be done /* //waiting for the last frame read to be done */
while(runBusy()) usleep(500); /* while(runBusy()) usleep(500); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("State machine stopped\n"); /* printf("State machine stopped\n"); */
#endif /* #endif */
} /* } */
val=bus_r(MULTI_PURPOSE_REG); /* val=bus_r(MULTI_PURPOSE_REG); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); /* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
#endif /* #endif */
bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT)); /* bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT)); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); /* printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
#endif /* #endif */
memcpy(counterVals,ptr,dataBytes);/*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*/ /* memcpy(counterVals,ptr,dataBytes);/\*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*\/ */
#ifdef VERBOSE /* #ifdef VERBOSE */
int i; /* int i; */
printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); /* printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); */
for(i=0;i<6;i=i+2) /* for(i=0;i<6;i=i+2) */
printf("%d: %d\t",i,*(counterVals+i)); /* printf("%d: %d\t",i,*(counterVals+i)); */
#endif /* #endif */
bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); /* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */
#ifdef VERBOSE /* #ifdef VERBOSE */
printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); /* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
#endif /* #endif */
if(startACQ==1){ /* if(startACQ==1){ */
startStateMachine(); /* startStateMachine(); */
if(runBusy()) /* if(runBusy()) */
printf("State machine RUNNING\n"); /* printf("State machine RUNNING\n"); */
else /* else */
printf("State machine IDLE\n"); /* printf("State machine IDLE\n"); */
} /* } */
if(sizeof(counterVals)<=0){ /* if(sizeof(counterVals)<=0){ */
printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals)); /* printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals)); */
ret = FAIL; /* ret = FAIL; */
} /* } */
return ret; return ret;
@ -3401,7 +3410,8 @@ uint64_t writePatternWord(int addr, uint64_t word) {
return readPatternWord(addr); return readPatternWord(addr);
} }
uint64_t writePatternIOControl(uint64_t word) { uint64_t writePatternIOControl(uint64_t word) {
if (word!=0xffffffffffffffff) { /*warning: integer constant is too large for long type*/ uint64_t c=0xffffffffffffffffULL;
if (word!=c) { /*warning: integer constant is too large for long type*/
// printf("%llx %llx %lld",get64BitReg(PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB),word); // printf("%llx %llx %lld",get64BitReg(PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB),word);
set64BitReg(word,PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB); set64BitReg(word,PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB);
// printf("************ write IOCTRL (%x)\n",PATTERN_IOCTRL_REG_MSB); // printf("************ write IOCTRL (%x)\n",PATTERN_IOCTRL_REG_MSB);
@ -3410,7 +3420,8 @@ uint64_t writePatternIOControl(uint64_t word) {
} }
uint64_t writePatternClkControl(uint64_t word) { uint64_t writePatternClkControl(uint64_t word) {
if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);/*warning: integer constant is too large for long type*/ uint64_t c=0xffffffffffffffffULL;
if (word!=c) 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); return get64BitReg(PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);
} }
@ -3555,7 +3566,7 @@ void initDac(int dacnum) {
printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx); printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx);
codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0)); /*warning: suggest parentheses around + or - inside shift*/ codata=(((0x6)<<4)|((0xf)<<16)|((0x0<<4)&0xfff0));
valw=0xffff; bus_w(offw,(valw)); // start point valw=0xffff; bus_w(offw,(valw)); // start point
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
@ -3592,7 +3603,7 @@ void initDac(int dacnum) {
} }
int setDacRegister(int dacnum,int dacvalue) { int setDacRegister(int dacnum,int dacvalue) {
int val; // int val;
/* if (dacvalue==-100) */ /* if (dacvalue==-100) */
/* dacvalue=0xffff; */ /* dacvalue=0xffff; */
@ -3679,6 +3690,10 @@ int setPower(int ind, int val) {
dacindex=23; dacindex=23;
pwrindex=0; pwrindex=0;
break; break;
case V_LIMIT:
dacindex=-1;
pwrindex=-1;
break;
default: default:
pwrindex=-1; pwrindex=-1;
dacindex=-1; dacindex=-1;
@ -3690,22 +3705,28 @@ int setPower(int ind, int val) {
} else { } else {
if (pwrindex>=0) { if (pwrindex>=0) {
printf("vpower\n"); printf("vpower\n");
dacval=((vmax-val)*4095)/(vmax-vmin); dacval=((vmax-val)*4095)/(vmax-vmin);
if (dacval<0) if (dacval<0)
dacval=0; dacval=0;
if (dacval>4095) if (dacval>4095)
dacval=-100; dacval=-100;
if (val==-100) if (val==-100)
dacval=-100; dacval=-100;
} else { } else if (dacindex>=0) {
printf("vchip\n"); printf("vchip\n");
dacval=((2700-val)*4095)/1000; dacval=((2700-val)*4095)/1000;
if (dacval<0) if (dacval<0)
dacval=0; dacval=0;
if (dacval>4095) if (dacval>4095)
dacval=4095; dacval=4095;
} else {
vLimit=val;
printf("vlimit %d\n",vLimit );
} }
} }
if (pwrindex>=0 && val!=-1) { if (pwrindex>=0 && val!=-1) {
@ -3746,12 +3767,16 @@ int setPower(int ind, int val) {
retval1=retval; retval1=retval;
} else } else
retval1=0; retval1=0;
} else { } else if (dacindex>=0) {
if (retval>=0) { if (retval>=0) {
retval1=2700-(retval*1000)/4095; retval1=2700-(retval*1000)/4095;
printf("Vchip id %d mV\n",vmax); printf("Vchip is %d mV\n",vmax);
} else } else
retval1=-1; retval1=-1;
} else {
printf("Get vlimit %d\n",vLimit);
retval=vLimit;
retval1=vLimit;
} }
/* switch (ind) { */ /* switch (ind) { */
@ -3781,15 +3806,17 @@ int setPower(int ind, int val) {
int powerChip(int arg) { int powerChip(int arg) {
//#ifndef CTB //#ifndef CTB
u_int32_t preg=bus_r(POWER_ON_REG);
if (arg>=0) { u_int32_t preg=bus_r(POWER_ON_REG);
if (arg) if (myDetectorType!=JUNGFRAUCTB) {
bus_w(POWER_ON_REG,preg|0xffff0000); if (arg>=0) {
else if (arg)
bus_w(POWER_ON_REG,preg&0x0000ffff); bus_w(POWER_ON_REG,preg|0xffff0000);
preg=bus_r(POWER_ON_REG); else
bus_w(POWER_ON_REG,preg&0x0000ffff);
preg=bus_r(POWER_ON_REG);
}
} }
printf("Power register is %08x\n",preg); printf("Power register is %08x\n",preg);
if (preg&0xffff0000) if (preg&0xffff0000)
return 1; return 1;
@ -3799,10 +3826,50 @@ int powerChip(int arg) {
int vLimitCompliant(int val_mV) {
int ret=0;
if (vLimit>0) {
if (val_mV<=vLimit) ret=1;
} else ret=1;
return ret;
}
int dacSPI(int codata) {
u_int32_t offw;
int valw, vv;
int i, ddx,cdx;
ddx=0; cdx=1;
offw=DAC_REG;
valw=bus_r(offw);
// codata=((cmd&0xf)<<DAC_CMD_OFF)|((val<<4)&0xfff0);
printf("%08x\n",codata);
valw=bus_r(offw);
for (i=1;i<33;i++) {
if ((codata&(1<<(32-i)))) {
vv=valw|(0x1<<ddx);
} else {
vv=valw&(~(0x1<<ddx));
}
printf("%x",vv&0x1);
bus_w16(offw,vv);//data
bus_w16(offw,vv|(0x1<<cdx));//clkup
bus_w16(offw,vv&(~(0x1<<cdx))); //cldwn
}
printf("\n");
return 1;
}
@ -3810,140 +3877,92 @@ int powerChip(int arg) {
int nextDac(){ int nextDac(){
u_int32_t offw,codata;
u_int16_t valw=bus_r(offw);
int i,ddx,csdx,cdx;
int dacch=0; return dacSPI(0xf<<DAC_CMD_OFF);
// printf("**************************************************next dac\n");
//setting int reference
offw=DAC_REG;
ddx=0; cdx=1;
csdx=2;
valw=0xffff&(~(0x1<<csdx));
if (myDetectorType==JUNGFRAUCTB)
for (i=0;i<8;i++) {
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
}
codata=((0xf)<<DAC_CMD_OFF); // no operation
// printf("%08x\n",codata);
// valw=0xffff;
// bus_w(offw,(valw)); // start point
// valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
for (i=1;i<25;i++) {
// printf("%d",((codata>>(24-i)))&0x1);
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=((valw&(~(0x1<<ddx)))+(((codata>>(24-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i)
// printf("%d ", ((codata>>(24-i))&0x1));
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
}
// printf("\n ");
// valw=((valw&(~(0x1<<csdx)))+(0x1<<csdx));bus_w(offw,valw); //csup
// valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
// valw=0xffff; bus_w(offw,(valw)); // stop point =start point of course */
} }
int setThisDac(int dacnum,int dacvalue){ int setThisDac(int dacnum, int dacvalue){
u_int32_t offw,codata; u_int32_t codata, cmd;
u_int16_t valw=bus_r(offw); /* u_int16_t valw=bus_r(offw); */
int i,ddx,csdx,cdx; /* int i,ddx,csdx,cdx; */
int dacch=0; int dacch;
/* //int val=dacvalue; */
ddx=0; cdx=1;
if (myDetectorType==JUNGFRAUCTB)
csdx=2;
else
csdx=dacnum/8+2;
dacch=dacnum%8; /* ddx=0; cdx=1; */
//setting int reference
offw=DAC_REG;
valw=0xffff&(~(0x1<<csdx));
/* if (myDetectorType==JUNGFRAUCTB) */ /* if (myDetectorType==JUNGFRAUCTB) */
/* for (i=0;i<8;i++) { */ /* csdx=2; */
/* valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn */ /* else */
/* valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup */ /* csdx=dacnum/8+2; */
dacch=dacnum%8;
/* //setting int reference */
/* offw=DAC_REG; */
/* valw= bus_r(offw);//0xffff; */
/* // if (myDetectorType==JUNGFRAUCTB) */
/* for (i=0;i<8;i++) { */
/* valw=(valw&(~(0x1<<cdx))); */
/* bus_w(offw,valw); //cldwn */
/* valw=(valw|(0x1<<cdx)); */
/* bus_w(offw,valw);//clkup */
/* } */ /* } */
// printf("**************************************************set dac\n"); /* // printf("**************************************************set dac\n"); */
if (dacvalue>=0) { if (dacvalue>=0) {
cmd=0x3;
// printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx);
//modified to power down single channels
// codata=((((0x2)<<4)+((dacch)&0xf))<<16)+((dacvalue<<4)&0xfff0);
codata=(0x3)<<DAC_CMD_OFF;
// codata=(((((0x3)<<DAC_CMD_OFF)&0xf00000)|((dacch)&0xf))<<16)|((dacvalue<<4)&0xfff0);
} else if (dacvalue==-100) { } else if (dacvalue==-100) {
// printf("switching off dac %d\n", dacnum); cmd=0x4;
codata=(0x4)<<DAC_CMD_OFF;
} }
// printf("%08x\n",codata); codata=cmd<<DAC_CMD_OFF;
codata=codata+((((dacch)&0xf))<<16)+((dacvalue<<4)&0xfff0); codata|=(dacch&0xf)<<16;
//printf("%08x\n",codata); codata|=(dacvalue&0xfff)<<4;
return dacSPI(codata);
/* // printf("%08x\n",codata); */
/* codata=codata|((((dacch)&0xf))<<16)|((dacvalue<<4)&0xfff0); */
/* printf("%08x\n",codata); */
for (i=1;i<25;i++) { /* for (i=1;i<25;i++) { */
// printf("%d",((codata>>(24-i)))&0x1); /* // printf("%d",((codata>>(24-i)))&0x1); */
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn /* valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn */
valw=((valw&(~(0x1<<ddx)))+(((codata>>(24-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i)
// printf("%d ", ((codata>>(24-i))&0x1)); /* valw=((valw&(~(0x1<<ddx)))+(((codata>>(24-i))&0x1)<<ddx)); */
/* bus_w(offw,valw);//write data (i) */
/* // printf("%d ", ((codata>>(24-i))&0x1)); */
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup /* valw=((valw)|(0x1<<cdx));bus_w(offw,valw);//clkup */
} /* } */
// printf("\n "); /* // printf("\n "); */
// printf("Writing %d in DAC(0-15) %d \n",dacvalue,dacnum); /* // printf("Writing %d in DAC(0-15) %d \n",dacvalue,dacnum); */
// printf("Writing %d in DAC(0-15) %d \n",dacvalue,dacnum); /* // printf("Writing %d in DAC(0-15) %d \n",dacvalue,dacnum); */
/* return 0; */
} }
@ -3957,12 +3976,12 @@ int setThisDac(int dacnum,int dacvalue){
int setDac(int dacnum,int dacvalue){ int setDac(int dacnum,int dacvalue){
u_int32_t offw,codata; u_int32_t offw;
u_int32_t ichip; u_int32_t ichip;
u_int16_t valw; u_int16_t valw;
int i,ddx,csdx,cdx; int i,ddx,csdx,cdx;
int dacch=0;
if (myDetectorType==JUNGFRAUCTB) if (myDetectorType==JUNGFRAUCTB)
ichip=2-dacnum/8; ichip=2-dacnum/8;
else else
@ -3983,33 +4002,37 @@ int setDac(int dacnum,int dacvalue){
offw=DAC_REG; offw=DAC_REG;
valw=0xffff; bus_w(offw,(valw)); // start point valw=bus_r(offw)|0xff; bus_w(offw,(valw)); // start point
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
//#ifdef CTB //#ifdef CTB
if (myDetectorType==JUNGFRAUCTB) for (i=0; i<ichip; i++) {nextDac();printf("next DAC\n");} if (myDetectorType==JUNGFRAUCTB) {
for (i=0; i<ichip; i++) {
nextDac();
printf("next DAC\n");
}
}
//#endif //#endif
printf("--------thisdac %d ",i); printf("--------thisdac %d \n",i);
setThisDac(dacnum,dacvalue); setThisDac(dacnum,dacvalue);
// printf("--------thisdac %d ",i); // printf("--------thisdac %d ",i);
// printf("--------after %d ",i); printf("--------done %d \n",i);
if (myDetectorType==JUNGFRAUCTB) { if (myDetectorType==JUNGFRAUCTB) {
nextDac(); for (i=ichip+1; i<N_DAC/8; i++) {
printf("next DAC\n"); nextDac();
printf("next DAC\n");
}
} }
valw=bus_r(offw); valw=bus_r(offw);
valw=(valw|(0x1<<csdx));bus_w(offw,valw); //csup valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=(valw|(0x1<<csdx));
// valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn bus_w(offw,valw); //csup
valw=bus_r(offw)|0xff; bus_w(offw,(valw)); // stop point =start point of course */
valw=0xffff; bus_w(offw,(valw)); // stop point =start point of course */
setDacRegister(dacnum,dacvalue); setDacRegister(dacnum,dacvalue);

View File

@ -219,4 +219,6 @@ int64_t setSamples(int64_t value);
int prepareSlowADCSeq(); int prepareSlowADCSeq();
int readSlowADC(int ichan); int readSlowADC(int ichan);
int setReadOutMode(int arg); int setReadOutMode(int arg);
int vLimitCompliant(int val_mV)
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -7,46 +7,30 @@
// Hardware definitions // Hardware definitions
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHAN 36 #define NCHAN 36
#define NCHIP 1 #define NCHIP 1
#define NADC 9 // #define NADC 9 //
#ifdef CTB /* #ifdef CTB */
#define NDAC 24 /* #define NDAC 24 */
#define NPWR 5 /* #define NPWR 5 */
#else /* #else */
#define NDAC 16 /* #define NDAC 16 */
#define NPWR 0 /* #define NPWR 0 */
#endif /* #endif */
#define DAC_CMD_OFF 20 #define DAC_CMD_OFF 20
#define NMAXMODX 1 #define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHANS (NCHAN*NCHIP*NMAXMOD) #define NCHANS (NCHAN*NCHIP*NMAXMOD)
#define NDACS (NDAC*NMAXMOD) #define NDACS (NDAC*NMAXMOD)
#define JUNGFRAU_NCHAN (256*256)
#define JUNGFRAU_NCHIP 8
#define JUNGFRAU_NADC 0
#define JUNGFRAU_NDAC 16
#define JUNGFRAU_NCHANS (JUNGFRAU_NCHAN*JUNGFRAU_NCHIP*NMAXMOD)
/**when moench readout tested with gotthard module*/ /**when moench readout tested with gotthard module*/
#define GOTTHARDNCHAN 128
#define GOTTHARDNCHIP 10
#define NTRIMBITS 6
#define NCOUNTBITS 24
#define NCHIPS_PER_ADC 2
//#define TRIM_DR ((2**NTRIMBITS)-1)
//#define COUNT_DR ((2**NCOUNTBITS)-1)
#define TRIM_DR (((int)pow(2,NTRIMBITS))-1) #define TRIM_DR (((int)pow(2,NTRIMBITS))-1)
#define COUNT_DR (((int)pow(2,NCOUNTBITS))-1) #define COUNT_DR (((int)pow(2,NCOUNTBITS))-1)

View File

@ -59,8 +59,9 @@ int adcvpp=0x4;
/** for jungfrau reinitializing macro later */ /** for jungfrau reinitializing macro later */
int N_CHAN=NCHAN; int N_CHAN=NCHAN;
int N_CHIP=NCHIP; int N_CHIP=NCHIP;
int N_DAC=NDAC; int N_DAC=24;
int N_ADC=NADC; int N_ADC=NADC;
int N_PWR=5;
int N_CHANS=NCHANS; int N_CHANS=NCHANS;
@ -94,22 +95,30 @@ int init_detector(int b, int checkType) {
case MOENCH03_MODULE_ID: case MOENCH03_MODULE_ID:
myDetectorType=MOENCH; myDetectorType=MOENCH;
printf("This is a MOENCH03 module %d\n",MOENCH); printf("This is a MOENCH03 module %d\n",MOENCH);
N_DAC=8;
N_PWR=0;
break; break;
case JUNGFRAU_MODULE_ID: case JUNGFRAU_MODULE_ID:
myDetectorType=JUNGFRAU; myDetectorType=JUNGFRAU;
printf("This is a Jungfrau module %d\n Not supported: exiting!", JUNGFRAU); printf("This is a Jungfrau module %d\n Not supported: exiting!", JUNGFRAU);
N_DAC=8;
N_PWR=0;
exit(1); exit(1);
break; break;
case JUNGFRAU_CTB_ID: case JUNGFRAU_CTB_ID:
myDetectorType=JUNGFRAUCTB; myDetectorType=JUNGFRAUCTB;
printf("This is a CTB %d\n", JUNGFRAUCTB); printf("This is a CTB %d\n", JUNGFRAUCTB);
N_DAC=24;
N_PWR=5;
break; break;
default: default:
myDetectorType=GENERIC; myDetectorType=GENERIC;
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET); printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
N_DAC=8;
N_PWR=0;
break; break;
} }
@ -118,102 +127,25 @@ int init_detector(int b, int checkType) {
//control server only-- //control server only--
if (b) { if (b) {
resetPLL(); resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET); bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0); bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT); bus_w16(CONTROL_REG, GB10_RESET_BIT);
bus_w16(CONTROL_REG, 0); bus_w16(CONTROL_REG, 0);
#ifdef MCB_FUNCS #ifdef MCB_FUNCS
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)); printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
if(myDetectorType == JUNGFRAU) // if(myDetectorType == JUNGFRAU)
initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/ initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/
dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/ dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/
printf("Initializing Detector\n"); printf("Initializing Detector\n");
//bus_w16(CONTROL_REG, SYNC_RESET); // reset registers //bus_w16(CONTROL_REG, SYNC_RESET); // reset registers
#endif #endif
if (myDetectorType==JUNGFRAUCTB) prepareSlowADCSeq();
prepareSlowADCSeq();
// testFpga();
// testRAM();
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
//moench specific
// setPhaseShiftOnce();
/*some registers set, which is in common with jungfrau, please check */
prepareADC(); 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
if(myDetectorType==JUNGFRAU){
/** for jungfrau reinitializing macro */
N_CHAN=JUNGFRAU_NCHAN;
N_CHIP=JUNGFRAU_NCHIP;
N_DAC=JUNGFRAU_NDAC;
N_ADC=JUNGFRAU_NADC;
N_CHANS=JUNGFRAU_NCHANS;
//set dacs
int retval = -1;
int dacvalues[14][2]={
{0, 1250}, //vout_cm
{10, 1053}, //vin_com
{1, 600}, //vb_sda
{11, 1000}, //vb_colbuf
{2, 3000}, //vb_test_cur
{3, 830}, //vcascp_pixbuf
{4, 1630}, //vcascn_pixbuf
{12, 750}, //vb_pixbuf
{6, 480}, //vref_ds
{5, 1000}, //vb_ds
{7, 400}, //vref_comp
{13, 1220}, //vb_comp
{8, 1500}, //vref_prech
{9, 3000}, //vdd_prot
};
for(i=0;i<14;++i){
retval=setDac(dacvalues[i][0], dacvalues[i][1]);
if(retval!=dacvalues[i][1])
printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval);
}
//power on the chips
bus_w(POWER_ON_REG,0x1);
//reset adc
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
writeADC(ADCREG2,0x40);
writeADC(ADCREG3,0xf);
writeADC(ADCREG4,0x3f);
//vrefs - configurable?
writeADC(ADCREG_VREFS,0x2);
//set ADCINVERSionreg (by trial and error)
bus_w(ADC_INVERSION_REG,0x453b2a9c);
//set adc_pipeline
bus_w(ADC_PIPELINE_REG,0x20); //same as ADC_OFFSET_REG
//set dbit_pipeline
bus_w(DBIT_PIPELINE_REG,0x100e);
usleep(1000000);//1s
//reset mem machine fifos fifos
bus_w(MEM_MACHINE_FIFOS_REG,0x4000);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//reset run control
bus_w(MEM_MACHINE_FIFOS_REG,0x0400);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//set default setting
setSettings(DYNAMICGAIN,-1);
}
//Initialization of acquistion parameters //Initialization of acquistion parameters
setFrames(-1); setFrames(-1);
setTrains(-1); setTrains(-1);
@ -221,7 +153,7 @@ int init_detector(int b, int checkType) {
setPeriod(-1); setPeriod(-1);
setDelay(-1); setDelay(-1);
setGates(-1); setGates(-1);
setTiming(GET_EXTERNAL_COMMUNICATION_MODE); setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
setMaster(GET_MASTER); setMaster(GET_MASTER);
setSynchronization(GET_SYNCHRONIZATION_MODE); setSynchronization(GET_SYNCHRONIZATION_MODE);
@ -238,13 +170,13 @@ int init_detector(int b, int checkType) {
// getDynamicRange(); // getDynamicRange();
/* both these functions setROI and allocateRAM should go into the control server part. */ /* both these functions setROI and allocateRAM should go into the control server part. */
if(myDetectorType!=JUNGFRAU){
int retvalsize,ret; int retvalsize,ret;
setROI(-1,NULL,&retvalsize,&ret); setROI(-1,NULL,&retvalsize,&ret);
allocateRAM(); allocateRAM();
}
setSamples(1); setSamples(1);
bus_w(DAC_REG,0xffff);
return OK; return OK;
} }
@ -1049,6 +981,7 @@ int set_dac(int file_des) {
int n; int n;
int val; int val;
int mV=0; int mV=0;
int v;
sprintf(mess,"Can't set DAC\n"); sprintf(mess,"Can't set DAC\n");
n = receiveDataOnly(file_des,arg,sizeof(arg)); n = receiveDataOnly(file_des,arg,sizeof(arg));
@ -1085,27 +1018,35 @@ int set_dac(int file_des) {
#ifdef MCB_FUNCS
if (ret==OK) { if (ret==OK) {
if (differentClients==1 && lockStatus==1) { if (differentClients==1 && lockStatus==1) {
ret=FAIL; ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP); sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{ } else{
if (ind<NDAC-NPWR) { if (ind<N_DAC-N_PWR) {
if (mV) { if (mV) {
if (val>2500)
v=val;
if (val>2500)
val=-1; val=-1;
printf("%d mV is ",val); printf("%d mV is ",val);
if (val>0) if (val>0)
val=val/2500*4095; val=val/2500*4095;
printf("%d DACu\n", val); printf("%d DACu\n", val);
} else if (val>4095) } else {
val=-1; v=val*2500/4095;
if (val>4095) {
val=-1;
}
}
if (vLimitCompliant(v))
retval=setDac(ind,val); retval=setDac(ind,val);
} else { } else {
switch (ind) { switch (ind) {
case ADC_VPP: case ADC_VPP:
@ -1130,23 +1071,36 @@ int set_dac(int file_des) {
case V_POWER_D: case V_POWER_D:
case V_POWER_IO: case V_POWER_IO:
case V_POWER_CHIP: case V_POWER_CHIP:
if (mV) {
if (vLimitCompliant(val))
retval=setPower(ind,val);
else
printf("********power %d exceeds voltage limits", ind);
} else
printf("********power %d should be set in mV instead od DACu", ind);
break;
case V_LIMIT:
if (mV) { if (mV) {
retval=setPower(ind,val); retval=setPower(ind,val);
} else } else
printf("********power %d should be set in mV instead od DACu", ind); printf("********power %d should be set in mV instead od DACu", ind);
break; break;
default: default:
printf("**********No dac with index %d\n",ind); printf("**********No dac with index %d\n",ind);
printf("**********%d %d\n",N_DAC,N_PWR);
ret=FAIL; ret=FAIL;
} }
} }
} }
} }
if(ret==OK){ if(ret==OK){
if (ind<NDAC-NPWR) { if (ind<N_DAC-N_PWR) {
if (mV) { if (mV) {
printf("%d DACu is ",retval); printf("%d DACu is ",retval);
retval1=2500*retval/4095; retval1=2500*retval/4095;
@ -1156,17 +1110,17 @@ int set_dac(int file_des) {
} else } else
retval1=retval; retval1=retval;
} }
#endif
#ifdef VERBOSE //#ifdef VERBOSE
printf("DAC set to %d V\n", retval); printf("DAC set to %d mV\n", retval);
#endif //#endif
if(ret==FAIL) if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval); printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
else{ else{
if (differentClients) if (differentClients)
ret=FORCE_UPDATE; ret=FORCE_UPDATE;
} }

View File

@ -1432,7 +1432,7 @@ int* multiSlsDetector::getDataFromDetector() {
if(!nodatadetectortype) if(!nodatadetectortype)
retval=new int[nel]; retval=new int[nel];
p=retval;
// cout << "multi: " << thisMultiDetector->dataBytes << endl; // cout << "multi: " << thisMultiDetector->dataBytes << endl;
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) { for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
@ -2251,11 +2251,11 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
dataout=fdata; dataout=fdata;
else { else {
if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) { if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) {
dataout=new double[thisMultiDetector->dataBytes/2];
nn=thisMultiDetector->dataBytes/2; nn=thisMultiDetector->dataBytes/2;
dataout=new double[nn];
} else { } else {
dataout=new double[thisMultiDetector->numberOfChannels];
nn=thisMultiDetector->numberOfChannels; nn=thisMultiDetector->numberOfChannels;
dataout=new double[nn];
} }
} }

View File

@ -801,7 +801,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
//update?!?!?!? //update?!?!?!?
if(thisDetector->myDetectorType==JUNGFRAUCTB) { if(thisDetector->myDetectorType==JUNGFRAUCTB) {
cout << "here2" << endl; // cout << "here2" << endl;
getTotalNumberOfChannels(); getTotalNumberOfChannels();
//thisDetector->nChan[X]=32; //thisDetector->nChan[X]=32;
//thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y]; //thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y];
@ -1703,8 +1703,9 @@ int slsDetector::getTotalNumberOfChannels() {
} }
thisDetector->nChans=thisDetector->nChan[X]; thisDetector->nChans=thisDetector->nChan[X];
thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB]; thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB];
cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl; } else
} cout << "det type is "<< thisDetector->myDetectorType << endl;
cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl;
return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
}; };
@ -3928,9 +3929,9 @@ int* slsDetector::getDataFromDetector(int *retval){
n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
//#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl; std::cout<< "Received "<< n << " data bytes" << std::endl;
//#endif #endif
if (n!=thisDetector->dataBytes) { if (n!=thisDetector->dataBytes) {
std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl; std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
thisDetector->stoppedFlag=1; thisDetector->stoppedFlag=1;
@ -3940,8 +3941,13 @@ int* slsDetector::getDataFromDetector(int *retval){
} }
return NULL; return NULL;
} }
// for (int ib=0; ib<thisDetector->dataBytes/8; ib++)
// cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ;
} }
// cout << "get data returning " << endl; // cout << "get data returning " << endl;
// cout << endl;
return retval; return retval;
}; };
@ -3956,8 +3962,8 @@ int* slsDetector::readAll(){
int fnum=F_READ_ALL; int fnum=F_READ_ALL;
int* retval; // check what we return! int* retval; // check what we return!
int i=0;
#ifdef VERBOSE #ifdef VERBOSE
int i=0;
std::cout<< "Reading all frames "<< std::endl; std::cout<< "Reading all frames "<< std::endl;
#endif #endif
if (thisDetector->onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
@ -3965,23 +3971,18 @@ int* slsDetector::readAll(){
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
while ((retval=getDataFromDetector())){ while ((retval=getDataFromDetector())){
#ifdef VERBOSE
i++; i++;
#ifdef VERBOSE
std::cout<< i << std::endl; std::cout<< i << std::endl;
//#else #endif
//std::cout << "-" << flush ;
#endif
dataQueue.push(retval); dataQueue.push(retval);
// std::cout<< "pushed" << std::endl;
} }
disconnectControl(); disconnectControl();
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "received "<< i<< " frames" << std::endl; std::cout<< "received "<< i<< " frames" << std::endl;
//#else #endif
// std::cout << std::endl;
#endif
return dataQueue.front(); // check what we return! return dataQueue.front(); // check what we return!
}; };
@ -4019,19 +4020,21 @@ int* slsDetector::startAndReadAll(){
int* retval; int* retval;
//#ifdef VERBOSE //#ifdef VERBOSE
#ifdef VERBOSE
int i=0; int i=0;
#endif
//#endif //#endif
startAndReadAllNoWait(); startAndReadAllNoWait();
//#ifdef VERBOSE //#ifdef VERBOSE
// std::cout<< "started" << std::endl; // std::cout<< "started" << std::endl;
//#endif //#endif
while ((retval=getDataFromDetector())){ while ((retval=getDataFromDetector())){
#ifdef VERBOSE #ifdef VERBOSE
i++; i++;
std::cout<< i << std::endl; std::cout<< i << std::endl;
//#else //#else
//std::cout<< "-" << flush; //std::cout<< "-" << flush;
#endif #endif
dataQueue.push(retval); dataQueue.push(retval);
//std::cout<< "pushed" << std::endl; //std::cout<< "pushed" << std::endl;
@ -5029,14 +5032,17 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
double *dataout; double *dataout;
if (fdata) { if (fdata) {
dataout=fdata; dataout=fdata;
// printf("not allocating fdata!\n"); // printf("not allocating fdata!\n");
} else { if (thisDetector->myDetectorType==JUNGFRAUCTB) nn=thisDetector->dataBytes/2;
} else {
if (thisDetector->myDetectorType==JUNGFRAUCTB) { if (thisDetector->myDetectorType==JUNGFRAUCTB) {
dataout=new double[thisDetector->dataBytes/2];
nn=thisDetector->dataBytes/2; nn=thisDetector->dataBytes/2;
dataout=new double[nn];
// std::cout<< "nn is "<< nn << std::endl;
} else { } else {
dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
nn=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; nn=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
@ -5044,30 +5050,31 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
// printf("allocating fdata!\n"); // printf("allocating fdata!\n");
} }
const int bytesize=8; const int bytesize=8;
int ival=0; int ival=0;
char *ptr=(char*)datain; char *ptr=(char*)datain;
char iptr; char iptr;
int nbits=thisDetector->dynamicRange; int nbits=thisDetector->dynamicRange;
int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
int ipos=0, ichan=0, ibyte; int ipos=0, ichan=0, ibyte;
if (thisDetector->timerValue[PROBES_NUMBER]==0) { if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) { if (thisDetector->myDetectorType==JUNGFRAUCTB) {
for (ichan=0; ichan<thisDetector->dataBytes/2; ichan++) { for (ichan=0; ichan<nn; ichan++) {
// // } // // }
dataout[ichan]=*((u_int16_t*)ptr); dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2; ptr+=2;
} }
} else { std::cout<< "decoded "<< ichan << " channels" << std::endl;
} else {
switch (nbits) { switch (nbits) {
case 1: case 1:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) { for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0x1; iptr=ptr[ibyte];//&0x1;
for (ipos=0; ipos<8; ipos++) { for (ipos=0; ipos<8; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf; // dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos))&0x1; ival=(iptr>>(ipos))&0x1;
@ -5078,7 +5085,7 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
break; break;
case 4: case 4:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) { for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0xff; iptr=ptr[ibyte];
for (ipos=0; ipos<2; ipos++) { for (ipos=0; ipos<2; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf; // dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos*4))&0xf; ival=(iptr>>(ipos*4))&0xf;
@ -5096,36 +5103,32 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
case 16: case 16:
for (ichan=0; ichan<nch; ichan++) { for (ichan=0; ichan<nch; ichan++) {
// dataout[ichan]=0; // dataout[ichan]=0;
ival=0; // ival=0;
for (ibyte=0; ibyte<2; ibyte++) { // for (ibyte=0; ibyte<2; ibyte++) {
iptr=ptr[ichan*2+ibyte]; // iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize))); // ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
} // }
dataout[ichan]=ival; dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
} }
break; break;
default: default:
if(thisDetector->myDetectorType == MYTHEN){ int mask=0xffffffff;
for (ichan=0; ichan<nch; ichan++) { if(thisDetector->myDetectorType == MYTHEN) mask=0xffffff;
ival=datain[ichan]&0xffffff; for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=ival; dataout[ichan]=datain[ichan]&mask;
} }
}
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
} }
} }
} else { } else {
for (ichan=0; ichan<nch; ichan++) { for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan]; dataout[ichan]=datain[ichan];
} }
} }
#ifdef VERBOSE //#ifdef VERBOSE
std::cout<< "decoded "<< ichan << " channels" << std::endl; //#endif
#endif
return dataout; return dataout;
} }

View File

@ -787,6 +787,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++; i++;
descrToFuncMap[i].m_pFuncName="v_limit"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++;
/* r/w timers */ /* r/w timers */
descrToFuncMap[i].m_pFuncName="temp_adc"; // descrToFuncMap[i].m_pFuncName="temp_adc"; //
@ -3816,6 +3820,8 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
dac=V_POWER_IO; dac=V_POWER_IO;
else if (cmd== "v_chip") else if (cmd== "v_chip")
dac=V_POWER_CHIP; dac=V_POWER_CHIP;
else if (cmd== "v_limit")
dac=V_LIMIT;
else else
return string("cannot decode dac ")+cmd; return string("cannot decode dac ")+cmd;
@ -3849,7 +3855,7 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
sprintf(answer,"%f",myDet->setDAC(-1,dac,mode)); sprintf(answer,"%f",myDet->setDAC(-1,dac,mode));
#endif #endif
if(mode) if(mode)
strcat(answer,"mV"); strcat(answer," mV");
return string(answer); return string(answer);
} }
@ -4007,7 +4013,7 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
return string("cannot set ")+cmd; return string("cannot set ")+cmd;
if (sscanf(args[0],"adc:%d",&idac)==1) { if (sscanf(args[0],"adc:%d",&idac)==1) {
printf("chiptestboard!\n"); // printf("chiptestboard!\n");
adc=(dacIndex)(idac+1000); adc=(dacIndex)(idac+1000);
} else if (cmd=="temp_adc") } else if (cmd=="temp_adc")
adc=TEMPERATURE_ADC; adc=TEMPERATURE_ADC;

View File

@ -174,8 +174,8 @@ int slsDetectorUtils::acquire(int delflag){
//resets frames caught in receiver //resets frames caught in receiver
if(receiver){ if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg); //cout << "lock"<< endl;
resetFramesCaught(); resetFramesCaught();
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
} }
@ -269,7 +269,7 @@ int slsDetectorUtils::acquire(int delflag){
aclog->addStep(getCurrentPosition(), getCurrentFileName()); aclog->addStep(getCurrentPosition(), getCurrentFileName());
if (eclog) if (eclog)
eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName()); eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName());
if (*correctionMask&(1<< I0_NORMALIZATION)) { if (*correctionMask&(1<< I0_NORMALIZATION)) {
@ -344,7 +344,7 @@ int slsDetectorUtils::acquire(int delflag){
} else } else
break; break;
while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;; // cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;; // cout << "done " << endl;;

View File

@ -101,6 +101,13 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
// cout << "decode 0"<< endl; // cout << "decode 0"<< endl;
// if (getDetectorsType()==MYTHEN) { // if (getDetectorsType()==MYTHEN) {
// for (int ib=0; ib<1000; ib++)
// cout << ((*(((u_int64_t*)myData)+ib))>>17&1) ;
// cout << endl;
fdata=decodeData(myData,nn, fdata); fdata=decodeData(myData,nn, fdata);
//#ifdef VERBOSE //#ifdef VERBOSE