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_D = 103, /**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 */
/* Always append functions hereafter!!! */
/* 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

View File

@ -120,23 +120,23 @@ int withGotthard = 0;
* why is this used anywhere instead of macro*/
int nChans=NCHAN;
int nChips=NCHIP;
int nDacs=NDAC;
int nAdcs=NADC;
//int nDacs;//=NDAC;
//int nAdcs=NADC;
extern enum detectorType myDetectorType;
/** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/
extern int N_CHAN;
extern int N_CHIP;
extern int N_DAC;
extern int N_ADC;
extern int N_CHANS;
extern int N_CHAN;
extern int N_CHIP;
extern int N_DAC;
extern int N_ADC;
extern int N_CHANS;
int analogEnable=1;
int digitalEnable=0;
int vLimit=-100;
@ -1267,10 +1267,8 @@ u_int32_t testRAM(void) {
int getNModBoard() {
if(myDetectorType == JUNGFRAU)
return 1;
else
return 32;//nModX;
}
int setNMod(int n) {
@ -1489,7 +1487,7 @@ int setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
// ROI retval[MAX_ROIS];
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");
if (nroi>=0) {
@ -1691,10 +1689,10 @@ int initHighVoltage(int val, int imod){
u_int32_t offw,codata;
u_int16_t valw, dacvalue;
int iru,i,ddx,csdx,cdx;
float alpha=0.55, fval=val;
int i,ddx,csdx,cdx;//iru,
float alpha=0.55;//, fval=val;
if (val>=0) {
if (val!=-1) {
if (val<60) {
dacvalue=0;
@ -1707,6 +1705,9 @@ int initHighVoltage(int val, int imod){
val=200.-(dacvalue-1)*alpha;
}
printf ("****************************** setting val %d, dacval %d\n",val, dacvalue);
if (val>=0) {
offw=DAC_REG;
ddx=8; csdx=10; cdx=9;
@ -1715,7 +1716,7 @@ int initHighVoltage(int val, int imod){
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
for (i=0;i<8;i++) {
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
@ -1727,12 +1728,18 @@ int initHighVoltage(int val, int imod){
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);
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 reg,nchips,mask,nchans;
/* int reg,nchips,mask,nchans; */
if(adc==-1) ROI_flag=0;
else ROI_flag=1;
/* if(adc==-1) ROI_flag=0; */
/* else ROI_flag=1; */
// setDAQRegister();//token timing
cleanFifo();//adc sync
/* // setDAQRegister();//token timing */
/* cleanFifo();//adc sync */
//with gotthard module
if(withGotthard){
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = GOTTHARDNCHIP;
nchans = GOTTHARDNCHAN;
mask = ACTIVE_ADC_MASK;
}
/* //with gotthard module */
/* if(withGotthard){ */
/* //set packet size */
/* ipPacketSize= DEFAULT_IP_PACKETSIZE; */
/* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */
/* //set channel mask */
/* nchips = GOTTHARDNCHIP; */
/* nchans = GOTTHARDNCHAN; */
/* mask = ACTIVE_ADC_MASK; */
/* } */
//with moench module all adc
else{/* if(adc==-1){*/
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = N_CHIP;
nchans = N_CHANS;
mask = ACTIVE_ADC_MASK;
}/*
//with moench module 1 adc -- NOT IMPLEMENTED
else{
ipPacketSize= ADC1_IP_PACKETSIZE;
udpPacketSize=ADC1_UDP_PACKETSIZE;
//set channel mask
nchips = NCHIPS_PER_ADC;
nchans = GOTTHARDNCHAN;
mask = 1<<adc;
}*/
/* //with moench module all adc */
/* else{/\* if(adc==-1){*\/ */
/* //set packet size */
/* ipPacketSize= DEFAULT_IP_PACKETSIZE; */
/* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */
/* //set channel mask */
/* nchips = N_CHIP; */
/* nchans = N_CHANS; */
/* mask = ACTIVE_ADC_MASK; */
/* }/\* */
/* //with moench module 1 adc -- NOT IMPLEMENTED */
/* else{ */
/* ipPacketSize= ADC1_IP_PACKETSIZE; */
/* udpPacketSize=ADC1_UDP_PACKETSIZE; */
/* //set channel mask */
/* nchips = NCHIPS_PER_ADC; */
/* nchans = GOTTHARDNCHAN; */
/* mask = 1<<adc; */
/* }*\/ */
//set channel mask
reg = (nchans*nchips)<<CHANNEL_OFFSET;
reg&=CHANNEL_MASK;
reg|=(ACTIVE_ADC_MASK & mask);
bus_w(CHIP_OF_INTRST_REG,reg);
/* //set channel mask */
/* reg = (nchans*nchips)<<CHANNEL_OFFSET; */
/* reg&=CHANNEL_MASK; */
/* reg|=(ACTIVE_ADC_MASK & mask); */
/* bus_w(CHIP_OF_INTRST_REG,reg); */
//#ifdef DDEBUG
printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG));
//#endif
/* //#ifdef DDEBUG */
/* printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); */
/* //#endif */
adcConfigured = adc;
/* adcConfigured = adc; */
return adcConfigured;
}
@ -1846,7 +1853,7 @@ ip.ip_destip = destip;
count=sizeof(ip);
addr=&(ip); /* warning: assignment from incompatible pointer type */
addr=(unsigned short*) (&(ip)); /* warning: assignment from incompatible pointer type */
while( count > 1 ) {
sum += *addr++;
count -= 2;
@ -1975,7 +1982,7 @@ volatile u_int32_t conf= bus_r(CONFIG_REG);
usleep(10000);
bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT);
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)
{
int i=0, j, mask=1;
int i=0, mask=1;//j,
volatile u_int16_t a;
bus_w16(DUMMY_REG,0);
if (ns==0) {
@ -2213,11 +2220,13 @@ u_int16_t* fifo_read_event(int ns)
}
}
if (digitalEnable) {
printf("+");
// printf("+");
bus_w16(DUMMY_REG,1<<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);
//bit17 is clkout
printf("%d",(*((u_int64_t*)now_ptr)>>17)&1);
now_ptr+=8;
}
@ -2544,16 +2553,16 @@ int writeADC(int addr, int val) {
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_int32_t valw;
int i, obit, ibit;
int obit, ibit;
int cnv_bit=16, sdi_bit=17, sck_bit=18;
int oval=0;
// int oval=0;
printf("Codata is %04x\n",codata);
@ -2601,25 +2610,25 @@ int prepareSlowADCSeq() {
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
return 0;
}
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) | (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;
u_int32_t valw;
int i, obit, ibit;
int obit, ibit;
int cnv_bit=16, sdi_bit=17, sck_bit=18;
int oval=0;
// int oval=0;
printf("Codata is %04x\n",codata);
@ -2667,7 +2676,7 @@ int prepareSlowADC(int ichan) {
bus_w(ADC_WRITE_REG,(valw));
usleep(20);
return 0;
}
@ -2677,13 +2686,13 @@ int prepareSlowADC(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_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;
@ -3114,57 +3123,57 @@ int setSynchronization(int s) {
int readCounterBlock(int startACQ, short int CounterVals[]){
//char *counterVals=NULL;
//counterVals=realloc(counterVals,dataBytes);
/* //char *counterVals=NULL; */
/* //counterVals=realloc(counterVals,dataBytes); */
u_int32_t val;
volatile u_int16_t *ptr;
/* u_int32_t val; */
/* volatile u_int16_t *ptr; */
u_int32_t address = COUNTER_MEMORY_REG;
ptr=(u_int16_t*)(CSP0BASE+address*2);
/* u_int32_t address = COUNTER_MEMORY_REG; */
/* ptr=(u_int16_t*)(CSP0BASE+address*2); */
if (runBusy()) {
if(stopStateMachine()==FAIL)
return FAIL;
//waiting for the last frame read to be done
while(runBusy()) usleep(500);
#ifdef VERBOSE
printf("State machine stopped\n");
#endif
}
/* if (runBusy()) { */
/* if(stopStateMachine()==FAIL) */
/* return FAIL; */
/* //waiting for the last frame read to be done */
/* while(runBusy()) usleep(500); */
/* #ifdef VERBOSE */
/* printf("State machine stopped\n"); */
/* #endif */
/* } */
val=bus_r(MULTI_PURPOSE_REG);
#ifdef VERBOSE
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
/* val=bus_r(MULTI_PURPOSE_REG); */
/* #ifdef VERBOSE */
/* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
/* #endif */
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);
for(i=0;i<6;i++)
printf("%d: %d\t",i,CounterVals[i]);
#endif
/* 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); */
/* for(i=0;i<6;i++) */
/* printf("%d: %d\t",i,CounterVals[i]); */
/* #endif */
bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT));
#ifdef VERBOSE
printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
/* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */
/* #ifdef VERBOSE */
/* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
/* #endif */
if(startACQ==1){
startStateMachine();
if(runBusy())
printf("State machine RUNNING\n");
else
printf("State machine IDLE\n");
}
/* if(startACQ==1){ */
/* startStateMachine(); */
/* if(runBusy()) */
/* printf("State machine RUNNING\n"); */
/* else */
/* printf("State machine IDLE\n"); */
/* } */
/* if(sizeof(CounterVals)<=0){
printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals));
return FAIL;
}*/
/* /\* if(sizeof(CounterVals)<=0){ */
/* printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals)); */
/* return FAIL; */
/* }*\/ */
return OK;
@ -3174,67 +3183,67 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
int resetCounterBlock(int startACQ){
char *counterVals=NULL;
counterVals=realloc(counterVals,dataBytes);
int ret = OK;
u_int32_t val;
volatile u_int16_t *ptr;
/* char *counterVals=NULL; */
/* counterVals=realloc(counterVals,dataBytes); */
/* u_int32_t val; */
/* volatile u_int16_t *ptr; */
u_int32_t address = COUNTER_MEMORY_REG;
ptr=(u_int16_t*)(CSP0BASE+address*2);
/* u_int32_t address = COUNTER_MEMORY_REG; */
/* ptr=(u_int16_t*)(CSP0BASE+address*2); */
if (runBusy()) {
if(stopStateMachine()==FAIL)
return FAIL;
//waiting for the last frame read to be done
while(runBusy()) usleep(500);
#ifdef VERBOSE
printf("State machine stopped\n");
#endif
}
/* if (runBusy()) { */
/* if(stopStateMachine()==FAIL) */
/* return FAIL; */
/* //waiting for the last frame read to be done */
/* while(runBusy()) usleep(500); */
/* #ifdef VERBOSE */
/* printf("State machine stopped\n"); */
/* #endif */
/* } */
val=bus_r(MULTI_PURPOSE_REG);
#ifdef VERBOSE
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
/* val=bus_r(MULTI_PURPOSE_REG); */
/* #ifdef VERBOSE */
/* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
/* #endif */
bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT));
#ifdef VERBOSE
printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
/* bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT)); */
/* #ifdef VERBOSE */
/* printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
/* #endif */
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));
for(i=0;i<6;i=i+2)
printf("%d: %d\t",i,*(counterVals+i));
#endif
/* 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)); */
/* for(i=0;i<6;i=i+2) */
/* printf("%d: %d\t",i,*(counterVals+i)); */
/* #endif */
bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT));
#ifdef VERBOSE
printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
/* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */
/* #ifdef VERBOSE */
/* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */
/* #endif */
if(startACQ==1){
startStateMachine();
if(runBusy())
printf("State machine RUNNING\n");
else
printf("State machine IDLE\n");
}
/* if(startACQ==1){ */
/* startStateMachine(); */
/* if(runBusy()) */
/* printf("State machine RUNNING\n"); */
/* else */
/* printf("State machine IDLE\n"); */
/* } */
if(sizeof(counterVals)<=0){
printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals));
ret = FAIL;
}
/* if(sizeof(counterVals)<=0){ */
/* printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals)); */
/* ret = FAIL; */
/* } */
return ret;
@ -3401,7 +3410,8 @@ uint64_t writePatternWord(int addr, uint64_t word) {
return readPatternWord(addr);
}
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);
set64BitReg(word,PATTERN_IOCTRL_REG_LSB,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) {
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);
}
@ -3555,7 +3566,7 @@ void initDac(int dacnum) {
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=((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 val;
// int val;
/* if (dacvalue==-100) */
/* dacvalue=0xffff; */
@ -3679,6 +3690,10 @@ int setPower(int ind, int val) {
dacindex=23;
pwrindex=0;
break;
case V_LIMIT:
dacindex=-1;
pwrindex=-1;
break;
default:
pwrindex=-1;
dacindex=-1;
@ -3698,14 +3713,20 @@ int setPower(int ind, int val) {
if (val==-100)
dacval=-100;
} else {
} else if (dacindex>=0) {
printf("vchip\n");
dacval=((2700-val)*4095)/1000;
if (dacval<0)
dacval=0;
if (dacval>4095)
dacval=4095;
} else {
vLimit=val;
printf("vlimit %d\n",vLimit );
}
}
if (pwrindex>=0 && val!=-1) {
@ -3746,12 +3767,16 @@ int setPower(int ind, int val) {
retval1=retval;
} else
retval1=0;
} else {
} else if (dacindex>=0) {
if (retval>=0) {
retval1=2700-(retval*1000)/4095;
printf("Vchip id %d mV\n",vmax);
printf("Vchip is %d mV\n",vmax);
} else
retval1=-1;
} else {
printf("Get vlimit %d\n",vLimit);
retval=vLimit;
retval1=vLimit;
}
/* switch (ind) { */
@ -3781,7 +3806,9 @@ int setPower(int ind, int val) {
int powerChip(int arg) {
//#ifndef CTB
u_int32_t preg=bus_r(POWER_ON_REG);
if (myDetectorType!=JUNGFRAUCTB) {
if (arg>=0) {
if (arg)
bus_w(POWER_ON_REG,preg|0xffff0000);
@ -3789,7 +3816,7 @@ int powerChip(int arg) {
bus_w(POWER_ON_REG,preg&0x0000ffff);
preg=bus_r(POWER_ON_REG);
}
}
printf("Power register is %08x\n",preg);
if (preg&0xffff0000)
return 1;
@ -3799,151 +3826,143 @@ 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 nextDac(){
u_int32_t offw,codata;
u_int16_t valw=bus_r(offw);
int i,ddx,csdx,cdx;
int dacch=0;
// printf("**************************************************next dac\n");
//setting int reference
offw=DAC_REG;
int dacSPI(int codata) {
u_int32_t offw;
int valw, vv;
int i, ddx,cdx;
ddx=0; cdx=1;
csdx=2;
offw=DAC_REG;
valw=bus_r(offw);
// codata=((cmd&0xf)<<DAC_CMD_OFF)|((val<<4)&0xfff0);
printf("%08x\n",codata);
valw=bus_r(offw);
valw=0xffff&(~(0x1<<csdx));
for (i=1;i<33;i++) {
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
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
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");
return 1;
// 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){
u_int32_t offw,codata;
u_int16_t valw=bus_r(offw);
int i,ddx,csdx,cdx;
int dacch=0;
ddx=0; cdx=1;
int nextDac(){
if (myDetectorType==JUNGFRAUCTB)
csdx=2;
else
csdx=dacnum/8+2;
return dacSPI(0xf<<DAC_CMD_OFF);
dacch=dacnum%8;
//setting int reference
offw=DAC_REG;
}
int setThisDac(int dacnum, int dacvalue){
u_int32_t codata, cmd;
/* u_int16_t valw=bus_r(offw); */
/* int i,ddx,csdx,cdx; */
int dacch;
/* //int val=dacvalue; */
/* ddx=0; cdx=1; */
valw=0xffff&(~(0x1<<csdx));
/* if (myDetectorType==JUNGFRAUCTB) */
/* csdx=2; */
/* else */
/* 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)))+(0x1<<cdx));bus_w(offw,valw);//clkup */
/* 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) {
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) {
// printf("switching off dac %d\n", dacnum);
codata=(0x4)<<DAC_CMD_OFF;
cmd=0x4;
}
// printf("%08x\n",codata);
codata=codata+((((dacch)&0xf))<<16)+((dacvalue<<4)&0xfff0);
//printf("%08x\n",codata);
codata=cmd<<DAC_CMD_OFF;
codata|=(dacch&0xf)<<16;
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++) {
// 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));
/* 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
}
/* 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){
u_int32_t offw,codata;
u_int32_t offw;
u_int32_t ichip;
u_int16_t valw;
int i,ddx,csdx,cdx;
int dacch=0;
if (myDetectorType==JUNGFRAUCTB)
ichip=2-dacnum/8;
else
@ -3983,33 +4002,37 @@ int setDac(int dacnum,int dacvalue){
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<<cdx)));bus_w(offw,valw); //cldwn
//#ifdef CTB
if (myDetectorType==JUNGFRAUCTB) for (i=0; i<ichip; i++) {nextDac();printf("next DAC\n");}
//#endif
printf("--------thisdac %d ",i);
setThisDac(dacnum,dacvalue);
// printf("--------thisdac %d ",i);
// printf("--------after %d ",i);
if (myDetectorType==JUNGFRAUCTB) {
for (i=0; i<ichip; i++) {
nextDac();
printf("next DAC\n");
}
}
//#endif
printf("--------thisdac %d \n",i);
setThisDac(dacnum,dacvalue);
// printf("--------thisdac %d ",i);
printf("--------done %d \n",i);
if (myDetectorType==JUNGFRAUCTB) {
for (i=ichip+1; i<N_DAC/8; i++) {
nextDac();
printf("next DAC\n");
}
}
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));
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 */
valw=bus_r(offw)|0xff; bus_w(offw,(valw)); // stop point =start point of course */
setDacRegister(dacnum,dacvalue);

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -7,46 +7,30 @@
// Hardware definitions
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHAN 36
#define NCHIP 1
#define NADC 9 //
#ifdef CTB
#define NDAC 24
#define NPWR 5
#else
#define NDAC 16
#define NPWR 0
#endif
/* #ifdef CTB */
/* #define NDAC 24 */
/* #define NPWR 5 */
/* #else */
/* #define NDAC 16 */
/* #define NPWR 0 */
/* #endif */
#define DAC_CMD_OFF 20
#define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHANS (NCHAN*NCHIP*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*/
#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 COUNT_DR (((int)pow(2,NCOUNTBITS))-1)

View File

@ -59,8 +59,9 @@ int adcvpp=0x4;
/** for jungfrau reinitializing macro later */
int N_CHAN=NCHAN;
int N_CHIP=NCHIP;
int N_DAC=NDAC;
int N_DAC=24;
int N_ADC=NADC;
int N_PWR=5;
int N_CHANS=NCHANS;
@ -94,22 +95,30 @@ int init_detector(int b, int checkType) {
case MOENCH03_MODULE_ID:
myDetectorType=MOENCH;
printf("This is a MOENCH03 module %d\n",MOENCH);
N_DAC=8;
N_PWR=0;
break;
case JUNGFRAU_MODULE_ID:
myDetectorType=JUNGFRAU;
printf("This is a Jungfrau module %d\n Not supported: exiting!", JUNGFRAU);
N_DAC=8;
N_PWR=0;
exit(1);
break;
case JUNGFRAU_CTB_ID:
myDetectorType=JUNGFRAUCTB;
printf("This is a CTB %d\n", JUNGFRAUCTB);
N_DAC=24;
N_PWR=5;
break;
default:
myDetectorType=GENERIC;
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
N_DAC=8;
N_PWR=0;
break;
}
@ -126,92 +135,15 @@ int init_detector(int b, int checkType) {
#ifdef MCB_FUNCS
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*/
dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/
printf("Initializing Detector\n");
//bus_w16(CONTROL_REG, SYNC_RESET); // reset registers
#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();
//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
@ -238,13 +170,13 @@ int init_detector(int b, int checkType) {
// getDynamicRange();
/* 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();
}
setSamples(1);
bus_w(DAC_REG,0xffff);
return OK;
}
@ -1049,6 +981,7 @@ int set_dac(int file_des) {
int n;
int val;
int mV=0;
int v;
sprintf(mess,"Can't set DAC\n");
n = receiveDataOnly(file_des,arg,sizeof(arg));
@ -1085,27 +1018,35 @@ int set_dac(int file_des) {
#ifdef MCB_FUNCS
if (ret==OK) {
if (differentClients==1 && lockStatus==1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if (ind<NDAC-NPWR) {
if (ind<N_DAC-N_PWR) {
if (mV) {
v=val;
if (val>2500)
val=-1;
printf("%d mV is ",val);
if (val>0)
val=val/2500*4095;
printf("%d DACu\n", val);
} else if (val>4095)
} else {
v=val*2500/4095;
if (val>4095) {
val=-1;
}
}
if (vLimitCompliant(v))
retval=setDac(ind,val);
} else {
switch (ind) {
case ADC_VPP:
@ -1130,23 +1071,36 @@ int set_dac(int file_des) {
case V_POWER_D:
case V_POWER_IO:
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) {
retval=setPower(ind,val);
} else
printf("********power %d should be set in mV instead od DACu", ind);
break;
default:
printf("**********No dac with index %d\n",ind);
printf("**********%d %d\n",N_DAC,N_PWR);
ret=FAIL;
}
}
}
}
if(ret==OK){
if (ind<NDAC-NPWR) {
if (ind<N_DAC-N_PWR) {
if (mV) {
printf("%d DACu is ",retval);
retval1=2500*retval/4095;
@ -1156,17 +1110,17 @@ int set_dac(int file_des) {
} else
retval1=retval;
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
//#ifdef VERBOSE
printf("DAC set to %d mV\n", retval);
//#endif
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
else{
if (differentClients)
ret=FORCE_UPDATE;
}

View File

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

View File

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

View File

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

View File

@ -344,7 +344,7 @@ int slsDetectorUtils::acquire(int delflag){
} else
break;
while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;;

View File

@ -101,6 +101,13 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
// cout << "decode 0"<< endl;
// 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);
//#ifdef VERBOSE