sorted out problem with CPU read out

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

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;
return 1;
}
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;
@ -1705,35 +1703,44 @@ int initHighVoltage(int val, int imod){
} else {
dacvalue=1.+(200.-val)/alpha;
val=200.-(dacvalue-1)*alpha;
}
}
printf ("****************************** setting val %d, dacval %d\n",val, dacvalue);
offw=DAC_REG;
if (val>=0) {
offw=DAC_REG;
ddx=8; csdx=10; cdx=9;
codata=((dacvalue)&0xff);
ddx=8; csdx=10; cdx=9;
codata=((dacvalue)&0xff);
valw=0xffff; 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=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
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<<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 */
printf("Writing %d in HVDAC \n",dacvalue);
bus_w(HV_REG,val);
}
}
valw=((valw&(~(0x1<<csdx)))+(0x1<<csdx));bus_w(offw,valw); //csup
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
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,14 +2220,16 @@ 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;
}
}
// bus_w16(DUMMY_REG,0); //
/* #ifdef TIMEDBG */
@ -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){
int ret = OK;
char *counterVals=NULL;
counterVals=realloc(counterVals,dataBytes);
/* char *counterVals=NULL; */
/* counterVals=realloc(counterVals,dataBytes); */
int ret = OK;
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 */
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;
@ -3690,22 +3705,28 @@ int setPower(int ind, int val) {
} else {
if (pwrindex>=0) {
printf("vpower\n");
dacval=((vmax-val)*4095)/(vmax-vmin);
if (dacval<0)
dacval=0;
if (dacval>4095)
dacval=-100;
if (val==-100)
dacval=-100;
dacval=((vmax-val)*4095)/(vmax-vmin);
if (dacval<0)
dacval=0;
if (dacval>4095)
dacval=-100;
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;
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,15 +3806,17 @@ int setPower(int ind, int val) {
int powerChip(int arg) {
//#ifndef CTB
u_int32_t preg=bus_r(POWER_ON_REG);
if (arg>=0) {
if (arg)
bus_w(POWER_ON_REG,preg|0xffff0000);
else
bus_w(POWER_ON_REG,preg&0x0000ffff);
preg=bus_r(POWER_ON_REG);
u_int32_t preg=bus_r(POWER_ON_REG);
if (myDetectorType!=JUNGFRAUCTB) {
if (arg>=0) {
if (arg)
bus_w(POWER_ON_REG,preg|0xffff0000);
else
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,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(){
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_int16_t valw=bus_r(offw);
int i,ddx,csdx,cdx;
u_int32_t codata, cmd;
/* u_int16_t valw=bus_r(offw); */
/* 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;
//setting int reference
offw=DAC_REG;
/* ddx=0; cdx=1; */
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 */
/* 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)); */
/* 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=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
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");}
if (myDetectorType==JUNGFRAUCTB) {
for (i=0; i<ichip; i++) {
nextDac();
printf("next DAC\n");
}
}
//#endif
printf("--------thisdac %d ",i);
printf("--------thisdac %d \n",i);
setThisDac(dacnum,dacvalue);
// printf("--------thisdac %d ",i);
// printf("--------after %d ",i);
printf("--------done %d \n",i);
if (myDetectorType==JUNGFRAUCTB) {
nextDac();
printf("next DAC\n");
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=0xffff; bus_w(offw,(valw)); // stop point =start point of course */
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
valw=(valw|(0x1<<csdx));
bus_w(offw,valw); //csup
valw=bus_r(offw)|0xff; bus_w(offw,(valw)); // stop point =start point of course */
setDacRegister(dacnum,dacvalue);