Merge branch 'master' of gitorious.psi.ch:sls_det_software/sls_detector_software

This commit is contained in:
Dhanya Maliakal 2015-02-10 16:00:09 +01:00
commit b54f3628ae
15 changed files with 496 additions and 429 deletions

View File

@ -401,7 +401,8 @@ enum speedVariable {
PHASE_SHIFT, /**< adds phase shift */
OVERSAMPLING, /**< oversampling for analog detectors */
ADC_CLOCK, /**< adc clock divider */
ADC_PHASE /**< adc clock phase */
ADC_PHASE, /**< adc clock phase */
ADC_PIPELINE /**< adc pipeline */
};

View File

@ -1,4 +1,5 @@
//#define TESTADC
#define TESTADC1
#include "server_defs.h"
@ -34,7 +35,10 @@ const int nModY=1;
int nModBoard;
int nModX=NMAXMOD;
int dynamicRange=16;//32;
int nSamples=1;
int dataBytes=NMAXMOD*NCHIP*NCHAN*2;
int storeInRAM=0;
int ROI_flag=0;
int adcConfigured=-1;
@ -50,7 +54,8 @@ int phase_shift=0;//DEFAULT_PHASE_SHIFT;
int ipPacketSize=DEFAULT_IP_PACKETSIZE;
int udpPacketSize=DEFAULT_UDP_PACKETSIZE;
u_int32_t clkDivider[2]={160,32};
u_int32_t clkDivider[2]={32,16};
int32_t clkPhase[2]={0,0};
int ififostart, ififostop, ififostep, ififo;
@ -307,28 +312,28 @@ int cleanFifo(){
int setDAQRegister()
{
u_int32_t addr, reg, val;
addr=DAQ_REG;
/* u_int32_t addr, reg, val; */
/* addr=DAQ_REG; */
//depended on adcval
int packetlength=0x7f;
if(!ROI_flag) packetlength=0x13f;
/* //depended on adcval */
/* int packetlength=0x7f; */
/* if(!ROI_flag) packetlength=0x13f; */
//depended on pcb rev
int tokenTiming = TOKEN_TIMING_REV2;
if((bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)==1)
tokenTiming= TOKEN_TIMING_REV1;
/* //depended on pcb rev */
/* int tokenTiming = TOKEN_TIMING_REV2; */
/* if((bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)==1) */
/* tokenTiming= TOKEN_TIMING_REV1; */
val = (packetlength<<16) + tokenTiming;
//val=34+(42<<8)+(packetlength<<16);
/* val = (packetlength<<16) + tokenTiming; */
/* //val=34+(42<<8)+(packetlength<<16); */
reg=bus_r(addr);
bus_w(addr,val);
reg=bus_r(addr);
//#ifdef VERBOSE
printf("DAQ reg 0x15:%x\n",reg);
//#endif
/* reg=bus_r(addr); */
/* bus_w(addr,val); */
/* reg=bus_r(addr); */
/* //#ifdef VERBOSE */
/* printf("DAQ reg 0x15:%x\n",reg); */
/* //#endif */
return OK;
}
@ -369,27 +374,30 @@ u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig) {
printf("*********** pll busy: %08x\n",bus_r(STATUS_REG)&PLL_RECONFIG_BUSY);
bus_w(PLL_PARAM_REG,val);
printf("param: %x\n",val);
// printf("param: %x\n",val);
vv=reg<<PLL_CNTR_ADDR_OFF;
bus_w(PLL_CNTRL_REG,vv);
printf("wrote: %08x\n",vv);
usleep(1000);
vv=(1<<PLL_CNTR_WRITE_BIT)|(reg<<PLL_CNTR_ADDR_OFF)|(trig<<15);
bus_w(PLL_CNTRL_REG,vv);//15 is trigger for the tap
usleep(10000);
// printf("wrote: %08x\n",vv);
// vv=(1<<PLL_CNTR_WRITE_BIT)|(reg<<PLL_CNTR_ADDR_OFF)|(trig<<15);
bus_w(PLL_CNTRL_REG,vv|(1<<PLL_CNTR_WRITE_BIT) );//15 is trigger for the tap
// printf("----------- pll busy: %08x\n",bus_r(STATUS_REG)&PLL_RECONFIG_BUSY);
// printf("wrote: %08x\n",vv);
// usleep(10000);
printf("wrote: %08x\n",vv);
usleep(1000);
vv=(reg<<PLL_CNTR_ADDR_OFF);
printf("wrote: %08x\n",vv);
// vv=(reg<<PLL_CNTR_ADDR_OFF);
// printf("wrote: %08x\n",vv);
bus_w(PLL_CNTRL_REG,vv);
usleep(1000);
usleep(10000);
printf("+++++++++ pll busy: %08x\n",bus_r(STATUS_REG)&PLL_RECONFIG_BUSY);
while(bus_r(STATUS_REG)&PLL_RECONFIG_BUSY) {
printf("set: reconfig busy");
}
// bus_w(PLL_CNTRL_REG,(1<<PLL_CNTR_READ_BIT)|(reg<<PLL_CNTR_ADDR_OFF));
// usleep(1000);
// val=bus_r(PLL_PARAM_OUT_REG);
@ -417,18 +425,18 @@ u_int32_t getPllReconfigReg(u_int32_t reg, int trig) {
usleep(100);
val=(1<<PLL_CNTR_READ_BIT)|(reg<<PLL_CNTR_ADDR_OFF)|(trig<<15);
printf("wrote: %08x\n",val);
// printf("wrote: %08x\n",val);
bus_w(PLL_CNTRL_REG,val);//15 is trigger for the tap
// printf("read: %08x\n",bus_r(PLL_CNTRL_REG));
usleep(100);
// usleep(100);
/* for (i=0; i<10; i++) { */
vv=bus_r(PLL_PARAM_OUT_REG);
printf("addr %x reg: %x\n",reg,vv);
// vv=bus_r(PLL_PARAM_OUT_REG);
// printf("addr %x reg: %x\n",reg,vv);
/* usleep(100); */
/* } */
val=(reg<<PLL_CNTR_ADDR_OFF);
printf("wrote: %08x\n",val);
// printf("wrote: %08x\n",val);
bus_w(PLL_CNTRL_REG,val);
usleep(100);
@ -448,6 +456,89 @@ void resetPLL() {
bus_w(PLL_CNTRL_REG, 0);
}
void configurePll(int i) {
u_int32_t l=0x0c;
u_int32_t h=0x0d;
u_int32_t val;
int32_t phase=0, inv=0, ic=0;
u_int32_t tot;
u_int32_t odd=1;//0;
// printf("PLL reconfig reset\N"); bus_w(PLL_CNTRL_REG,(1<<PLL_CNTR_RECONFIG_RESET_BIT)); usleep(100); bus_w(PLL_CNTRL_REG, 0);
printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,1,0);
// usleep(10000);
if (i<2) {
tot= PLL_VCO_FREQ_MHZ/clkDivider[i];
l=tot/2;
h=l;
if (tot>2*l) {
h=l+1;
odd=1;
}
printf("Counter %d: Low is %d, High is %d\n",i, l,h);
val= (i<<18)| (odd<<17) | l | (h<<8);
printf("Counter %d, val: %08x\n", i, val); setPllReconfigReg(PLL_C_COUNTER_REG, val,0);
// usleep(20);
} else {
// if (mode==1) {
// } else {
printf("phase in %d\n",clkPhase[0]);
if (clkPhase[0]>0) {
inv=0;
phase=clkPhase[0];
} else {
inv=1;
phase=-1*clkPhase[0];
}
printf("phase out %d %08x\n",phase,phase);
val=phase | (inv<<16);;// | (inv<<21);
printf("Phase, val: %08x\n", val); setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0
}
printf("Start reconfig\n"); setPllReconfigReg(PLL_START_REG, 1,0);
// bus_w(PLL_CNTRL_REG, 0);
printf("Status register\n"); getPllReconfigReg(PLL_STATUS_REG,0);
// sleep(1);
// printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,0,0);
usleep(10000);
/* if (mode!=1) { */
/* printf("reset pll\n"); */
/* bus_w(PLL_CNTRL_REG,((1<<PLL_CNTR_PLL_RESET_BIT))); //reset PLL */
/* usleep(100); */
/* bus_w(PLL_CNTRL_REG, 0); */
/* } */
}
u_int32_t setClockDivider(int d, int ic) {
@ -456,10 +547,9 @@ u_int32_t setClockDivider(int d, int ic) {
u_int32_t val;
int i;
u_int32_t tot=800/d;
u_int32_t tot= PLL_VCO_FREQ_MHZ/d;
u_int32_t odd=0;
// int ic=0 is run clk; ic=1 is adc clk
printf("set clk divider %d to %d\n", ic, d);
if (ic>1)
@ -480,54 +570,17 @@ u_int32_t setClockDivider(int d, int ic) {
clkDivider[ic]=d;
configurePll(ic);
bus_w(PLL_CNTRL_REG,(1<<PLL_CNTR_RECONFIG_RESET_BIT)); //reset pll reconfig
usleep(100);
bus_w(PLL_CNTRL_REG, 0);
usleep(10000);
setPllReconfigReg(PLL_MODE_REG,1,0);
usleep(10000);
// getPllReconfigReg(PLL_MODE_REG,0);
for (i=0; i<1; i++) {
tot=800/clkDivider[i];
l=tot/2;
h=l;
if (tot>2*l) {
h=l+1;
odd=1;
}
printf("Counter %d: Low is %d, High is %d\n",i, l,h);
val= (i<<18)| (odd<<17) | l | (h<<8);
printf("Counter %d, val: %08x\n", i, val);
setPllReconfigReg(PLL_C_COUNTER_REG, val,0);
usleep(10000);
}
setPllReconfigReg(PLL_START_REG, 1,1);
usleep(100000);
bus_w(PLL_CNTRL_REG, 0);
return clkDivider[ic];
}
int phaseStep(int st, int ic){
u_int32_t addr;
u_int32_t addr, val=( (1<<PLL_CNTR_UPDN_BIT)| (1<<PLL_CNTR_CNTSEL_OFF) | (1<< PLL_CNTR_PHASE_EN_BIT));
/* int ic=0 is run clk; ic=1 is adc clk */
/* if (st>0) */
@ -537,25 +590,30 @@ int phaseStep(int st, int ic){
/* st*=-1; */
/* } */
bus_w(PLL_CNTRL_REG,(1<<PLL_CNTR_RECONFIG_RESET_BIT)); //reset PLL and pll reconfig
usleep(100);
bus_w(PLL_CNTRL_REG, 0);
int i;
if (st>65535 || st<-65535)
return -1;
bus_w(PLL_CNTRL_REG, 0);
setPllReconfigReg(PLL_MODE_REG,1,0);
getPllReconfigReg(PLL_MODE_REG,0);
printf("ic=%d; phase %d\n", ic, st);
setPllReconfigReg(PLL_PHASE_SHIFT_REG,st|(ic<<21),0); //shifts counter 0
printf("shift %08x\n",st|(ic<<21));
setPllReconfigReg(PLL_START_REG, 1,1);
usleep(100000);
bus_w(PLL_CNTRL_REG, 0);
//setClockDivider(clkDivider[ic],ic);
if (ic==1)
clkPhase[0]=-st;
else if (ic==0)
clkPhase[0]=st;
return st;
/* printf("Changin phase %d\n",st); */
/* for (i=0; i<st; i++) { */
/* bus_w(PLL_CNTRL_REG,0); */
/* bus_w(PLL_CNTRL_REG,val); */
/* } */
/* sleep(1); */
// bus_w(PLL_CNTRL_REG,0);
configurePll(2);
return clkPhase[0];
}
@ -597,6 +655,14 @@ u_int32_t getClockDivider(int ic) {
}
u_int32_t adcPipeline(int d) {
if (d>=0)
bus_w(DAQ_REG, d);
return bus_r(DAQ_REG)&0xff;
}
u_int32_t setSetLength(int d) {
return 0;
}
@ -973,15 +1039,15 @@ int startReceiver(int start) {
int reg=bus_r(addr);
//for start recever, write 0 and for stop, write 1
if (!start)
bus_w(CONFIG_REG,reg|CPU_OR_RECEIVER_BIT);
bus_w(CONFIG_REG,reg&(~GB10_NOT_CPU_BIT));
else
bus_w(CONFIG_REG,reg&(~CPU_OR_RECEIVER_BIT));
bus_w(CONFIG_REG,reg|GB10_NOT_CPU_BIT);
reg=bus_r(addr);
//#ifdef VERBOSE
printf("Config Reg %x\n", reg);
//#endif
int d =reg&CPU_OR_RECEIVER_BIT;
int d =reg&GB10_NOT_CPU_BIT;
if(d!=0) d=1;
if(d!=start)
return OK;
@ -1146,12 +1212,12 @@ int64_t getFrames(){
int64_t setExposureTime(int64_t value){
/* time is in ns */
if (value!=-1)
value*=(1E-9*CLK_FREQ);
return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
value*=(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t getExposureTime(){
return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t setGates(int64_t value){
@ -1165,28 +1231,29 @@ int64_t getGates(){
int64_t setPeriod(int64_t value){
/* time is in ns */
if (value!=-1) {
value*=(1E-9*CLK_FREQ);
// value*=(1E-9*CLK_FREQ);
value*=(1E-3*clkDivider[0]);
}
return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ);
return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t getPeriod(){
return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ);
return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t setDelay(int64_t value){
/* time is in ns */
if (value!=-1) {
value*=(1E-9*CLK_FREQ);
value*=(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ);
return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t getDelay(){
return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ);
return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
int64_t setTrains(int64_t value){
@ -1477,7 +1544,7 @@ int setADC(int adc){
if(adc==-1) ROI_flag=0;
else ROI_flag=1;
setDAQRegister();//token timing
// setDAQRegister();//token timing
cleanFifo();//adc sync
//with gotthard module
@ -1894,144 +1961,80 @@ u_int32_t fifo_full(void)
u_int16_t* fifo_read_event()
{
int i=0;
int i=0, j=0;
#ifdef VIRTUAL
return NULL;
#endif
//#ifdef VERBOSE
printf("before looping\n");
volatile u_int32_t fs;
u_int16_t *dum;
//#endif
volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG);
#ifdef VERBOSE
printf("Data bytes is %d\n", dataBytes);
printf("lookatmereg=x%x\n",t);
#endif
/*
while ((t&0x1)==0)
{
t = bus_r(LOOK_AT_ME_REG);
if (!runBusy()){
return NULL;
}
}
*/
bus_w(DUMMY_REG,0);
while(t==0) {
#ifdef VERYVERBOSE
printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
#endif
#ifdef VERYVERBOSE
printf("look at me reg:%08x\n",bus_r(LOOK_AT_ME_REG));
#endif
while(t!=0xffffffff) {
if (runBusy()==0) {
t = bus_r(LOOK_AT_ME_REG);
#ifdef VERYVERBOSE
printf("status should be idle!..look at me reg:%08x\n",bus_r(LOOK_AT_ME_REG));
#endif
if (t==0) {
//#ifdef VERBOSE
printf("no frame found - exiting\n");
if (t!=0xffffffff) {
printf("no frame found and acquisition finished - exiting\n");
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
//#endif
#ifdef VERYVERBOSE
printf("returning null\n");
printf("lookatmereg=x%x\n",t);
#endif
return NULL;
} else {
//#ifdef VERBOSE
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
//#endif
// printf("status idle, look at me %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
break;
}
}
t = bus_r(LOOK_AT_ME_REG);
#ifdef VERYVERBOSE
printf("before starting while loop again: look at me reg:%08x\n\n",bus_r(LOOK_AT_ME_REG));
#endif
if (i%1000==0)
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
i++;
printf(".");
}
#ifdef VERYVERBOSE
printf(" out of while loop!\n");
#endif
#ifdef VERYVERBOSE
printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
i=0;
for (i=0; i<32; i++) {
// printf("Fifo %d (%04x) status :\n", i,FIFO_STATUS_REG | i);
fs=bus_r16(FIFO_STATUS_REG| i);
if (fs&0xfff0fff)
printf("before %d: %x\n",i, fs);
}
#endif
// printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
/* dma_memcpy(now_ptr,values ,dataBytes); */
/* #else */
for (i=0; i<32; i++) {
dum=((u_int16_t*)(now_ptr))+i;
bus_w(DUMMY_REG,i<<1);
#ifdef TESTADC
printf("%d s:%04x ",i,bus_r16(FIFO_STATUS_REG));
#endif
// usleep(10);
bus_w(DUMMY_REG,(i<<1) | 1);
// usleep(10);
bus_w(DUMMY_REG,i<<1);
*dum=bus_r16(FIFO_DATA_REG);// | i); //values[i];
#ifdef TESTADC
printf("d:%04x s:%04x\n",*dum&0x3fff, bus_r16(FIFO_STATUS_REG));
#endif
/* usleep(10); */
*dum=bus_r16(FIFO_DATA_REG);
}
//#endif
printf("-");
//memcpy(now_ptr,values ,dataBytes); //this reads the fifo twice...
#ifdef VERYVERBOSE
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
i=0;
for (i=0; i<32; i++) {
fs=bus_r16(FIFO_STATUS_REG| i);
if (fs&0xfff0fff)
printf("after %d: %x\n",i, fs);
}
#endif
#ifdef VERYVERBOSE
int a;
for (a=0;a<8; a=a+2)
printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) );
// for (a=2554;a<2560; a=a+2)
// printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) );
printf("********\n");
//memcpy(now_ptr, values, dataBytes);
//#endif
//#ifdef VERYVERBOSE
printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes);
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
#endif
if (storeInRAM>0) {
now_ptr+=dataBytes;
}
#ifdef VERYVERBOSE
printf("lookatmereg=x%x\n",t);
#endif
printf("*");
return ram_values;
printf("\n");
}
u_int16_t* fifo_read_frame()
{
u_int16_t *dum;
int ns=0;
now_ptr=(char*)ram_values;
while(ns<nSamples) {
dum=fifo_read_event();
if (dum==NULL) break;
now_ptr+=dataBytes;
ns++;
}
// printf("%x %d\n",dum, ns);
if (ns==0) return NULL;
printf("+\n");
return ram_values;
}
u_int32_t* decode_data(int *datain)
{
u_int32_t *dataout;
@ -2097,6 +2100,14 @@ u_int32_t* decode_data(int *datain)
int setDynamicRange(int dr) {
if (dr%16==0 && dr>0) {
dynamicRange=16;
nSamples=dr/16;
dataBytes=NMAXMOD*NCHIP*NCHAN*2;
}
allocateRAM();
printf("Setting dataBytes to %d: dr %d; samples %d\n",dataBytes, dynamicRange, nSamples);
return getDynamicRange();
}
@ -2106,8 +2117,8 @@ int setDynamicRange(int dr) {
int getDynamicRange() {
dynamicRange=16;
return dynamicRange;
// dynamicRange=16;
return dynamicRange*nSamples;
}
@ -2156,18 +2167,9 @@ int setStoreInRAM(int b) {
int allocateRAM() {
size_t size;
u_int32_t nt, nf;
nt=setTrains(-1);
nf=setFrames(-1);
if (nt==0) nt=1;
if (nf==0) nf=1;
// ret=clearRAM();
if (storeInRAM) {
size=dataBytes*nf*nt;
if (size<dataBytes)
size=dataBytes;
} else
size=dataBytes;
size=dataBytes*nSamples;
#ifdef VERBOSE
printf("\nnmodx=%d nmody=%d dynamicRange=%d dataBytes=%d nFrames=%d nTrains=%d, size=%d\n",nModX,nModY,dynamicRange,dataBytes,nf,nt,(int)size );
@ -2175,50 +2177,43 @@ int allocateRAM() {
if (size==ram_size) {
#ifdef VERBOSE
//#ifdef VERBOSE
printf("RAM of size %d already allocated: nothing to be done\n",(int) size);
#endif
//#endif
return OK;
}
#ifdef VERBOSE
printf("reallocating ram %x\n",(unsigned int)ram_values);
#endif
// clearRAM();
// ram_values=malloc(size);
//#ifdef VERBOSE
printf("reallocating ram %x, size %d\n",(unsigned int)ram_values, size);
//#endif
//+2 was added since dma_memcpy would switch the 16 bit values and the mem is 32 bit
ram_values=realloc(ram_values,size)+2;
// while (nSamples>1) {
clearRAM();
ram_values=malloc(size);
// ram_values=realloc(ram_values,size)+2;
// if (ram_values)
// break;
// nSamples--;
//}
if (ram_values) {
now_ptr=(char*)ram_values;
#ifdef VERBOSE
//#ifdef VERBOSE
printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size));
#endif
//#endif
ram_size=size;
return OK;
} else {
printf("could not allocate %d bytes\n",(int)size);
if (storeInRAM==1) {
printf("retrying\n");
storeInRAM=0;
size=dataBytes;
ram_values=realloc(ram_values,size)+2;
if (ram_values==NULL)
printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n");
else {
now_ptr=(char*)ram_values;
ram_size=size;
#ifdef VERBOSE
printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size));
#endif
}
} else {
printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n");
}
return FAIL;
}
@ -2284,8 +2279,6 @@ int prepareADC(){
codata=0;
writeADC(0x08,0x3);
writeADC(0x08,0x0);
writeADC(0x14,0x40);//lvds reduced range
// writeADC(0x14,0x00);//lvds
writeADC(0x16,0x01);//output clock phase
@ -2293,6 +2286,10 @@ int prepareADC(){
// writeADC(0x16,0x4);//output clock phase
writeADC(0x18,0x0);// vref 1V
writeADC(0x14,0x40);//lvds reduced range -- offset binary
writeADC(0xD,0x0);//no test mode
#ifdef TESTADC
@ -2330,7 +2327,7 @@ int prepareADC(){
bus_w(ADC_LATCH_DISABLE_REG,0x0); // enable all ADCs
bus_w(DAQ_REG,0xd); //adc pipeline=13
bus_w(DAQ_REG,0x12); //adc pipeline=18
bus_w(ADC_OFFSET_REG,0xbbbbbbbb);
// bus_w(ADC_INVERSION_REG,0x1f6170c6);

View File

@ -51,6 +51,7 @@ u_int32_t getTotClockDivider();
u_int32_t setTotDutyCycle(int d);
u_int32_t getTotDutyCycle();
u_int32_t setOversampling(int d);
u_int32_t adcPipeline(int d);
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
int getExtSignal(int d);
@ -134,6 +135,7 @@ u_int32_t fifo_full(void);
u_int16_t* fifo_read_event();
u_int16_t* fifo_read_frame();
u_int32_t* decode_data(int* datain);
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
int setDynamicRange(int dr);

View File

@ -392,7 +392,7 @@
#define TOT_ENABLE_BIT 0x00000002
#define TIMED_GATE_BIT 0x00000004
#define CONT_RO_ENABLE_BIT 0x00080000
#define CPU_OR_RECEIVER_BIT 0x00001000
#define GB10_NOT_CPU_BIT 0x00001000
@ -503,6 +503,15 @@
#define PLL_CNTR_WRITE_BIT 2
#define PLL_CNTR_PLL_RESET_BIT 3
#define PLL_CNTR_PHASE_EN_BIT 8
#define PLL_CNTR_UPDN_BIT 9
#define PLL_CNTR_CNTSEL_OFF 10
#define PLL_MODE_REG 0x0
#define PLL_STATUS_REG 0x1
#define PLL_START_REG 0x2
@ -525,6 +534,8 @@
#define PPL_BW_PARAM_DEFAULT 0x2EE0
#define PPL_VCO_PARAM_DEFAULT 0x1
#define PLL_VCO_FREQ_MHZ 480//800

View File

@ -34,6 +34,7 @@ enum detectorType myDetectorType=GENERIC;
extern int nModX;
extern int nModY;
extern int dataBytes;
extern int nSamples;
extern int dynamicRange;
extern int storeInRAM;
@ -153,6 +154,8 @@ int init_detector(int b, int checkType) {
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
lockStatus=0;
allocateRAM();
return OK;
}
@ -1938,6 +1941,11 @@ int get_run_status(int file_des) {
int read_frame(int file_des) {
int ns=0;
u_int16_t* p=NULL;
if (differentClients==1 && lockStatus==1) {
dataret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
@ -1949,61 +1957,21 @@ int read_frame(int file_des) {
return dataret;
}
if (storeInRAM==0) {
if ((dataretval=(char*)fifo_read_event())) {
dataret=OK;
#ifdef VERYVERBOSE
printf("Sending ptr %x %d\n",(unsigned int)(dataretval), dataBytes);
#endif
sendDataOnly(file_des,&dataret,sizeof(dataret));
sendDataOnly(file_des,dataretval,dataBytes);
#ifdef VERBOSE
printf("sent %d bytes \n",dataBytes);
printf("dataret OK\n");
#endif
return OK;
} else {
//might add delay????
if(getFrames()>-1) {
dataret=FAIL;
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+1));
printf("%s\n",mess);
} else {
dataret=FINISHED;
sprintf(mess,"acquisition successfully finished\n");
printf("%s\n",mess);
}
#ifdef VERYVERBOSE
printf("%d %d %x %s\n",(int)(sizeof(mess)),(int)(strlen(mess)),(unsigned int)( mess),mess);
#endif
sendDataOnly(file_des,&dataret,sizeof(dataret));
sendDataOnly(file_des,mess,sizeof(mess));
#ifdef VERYVERBOSE
printf("message sent %s\n",mess);
#endif
printf("dataret %d\n",dataret);
return dataret;
}
} else {
nframes=0;
while(fifo_read_event()) {
p=fifo_read_frame();
if (p) {
nframes++;
}
dataretval=(char*)ram_values;
dataret=OK;
#ifdef VERBOSE
printf("sending data of %d frames\n",nframes);
#endif
for (iframes=0; iframes<nframes; iframes++) {
sendDataOnly(file_des,&dataret,sizeof(dataret));
#ifdef VERYVERBOSE
printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes);
printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes*nSamples);
#endif
sendDataOnly(file_des,dataretval,dataBytes);
dataretval+=dataBytes;
}
if (getFrames()>-2) {
sendDataOnly(file_des,dataretval,dataBytes*nSamples);
} else {
if (getFrames()>-1) {
dataret=FAIL;
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
printf("%s\n",mess);
@ -2019,11 +1987,9 @@ int read_frame(int file_des) {
#endif
sendDataOnly(file_des,&dataret,sizeof(dataret));
sendDataOnly(file_des,mess,sizeof(mess));
printf("dataret %d\n",dataret);
return dataret;
}
printf("dataret %d\n",dataret);
return dataret;
}
@ -2164,9 +2130,9 @@ int set_timer(int file_des) {
printf(mess);
printf("set timer failed\n");
} else if (ind==FRAME_NUMBER) {
ret=allocateRAM();
if (ret!=OK)
sprintf(mess, "could not allocate RAM for %lld frames\n", tns);
// ret=allocateRAM();
// if (ret!=OK)
// sprintf(mess, "could not allocate RAM for %lld frames\n", tns);
}
n = sendDataOnly(file_des,&ret,sizeof(ret));
@ -2291,7 +2257,7 @@ int set_dynamic_range(int file_des) {
int retval;
int ret=OK;
printf("Set dynamic range?\n");
sprintf(mess,"can't set dynamic range\n");
@ -2313,10 +2279,11 @@ int set_dynamic_range(int file_des) {
if (ret!=OK) {
sprintf(mess,"set dynamic range failed\n");
} else {
ret=allocateRAM();
if (ret!=OK)
sprintf(mess,"Could not allocate RAM for the dynamic range selected\n");
else if (differentClients)
/* ret=allocateRAM(); */
/* if (ret!=OK) */
/* sprintf(mess,"Could not allocate RAM for the dynamic range selected\n"); */
// else
if (differentClients)
ret=FORCE_UPDATE;
}
@ -2457,6 +2424,11 @@ int set_speed(int file_des) {
break;
case ADC_PIPELINE:
retval=adcPipeline(val);
break;
default:
ret=FAIL;
@ -2486,6 +2458,15 @@ int set_speed(int file_des) {
retval=getClockDivider(1);
break;
case ADC_PHASE:
retval=-1;
break;
case ADC_PIPELINE:
retval=adcPipeline(-1);
break;
default:
ret=FAIL;

View File

@ -612,6 +612,10 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8;
if(thisDetector->myDetectorType==JUNGFRAUCTB) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->dynamicRange/8;
}
if(thisDetector->myDetectorType==MYTHEN){
if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0)
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
@ -1540,6 +1544,11 @@ int slsDetector::setNumberOfModules(int n, dimension d){
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
}
if(thisDetector->myDetectorType==JUNGFRAUCTB){
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*dr/8;
}
#ifdef VERBOSE
std::cout<< "Data size is " << thisDetector->dataBytes << std::endl;
@ -3363,9 +3372,9 @@ int* slsDetector::getDataFromDetector(int *retval){
} else {
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: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
thisDetector->stoppedFlag=1;
@ -3376,7 +3385,7 @@ int* slsDetector::getDataFromDetector(int *retval){
return NULL;
}
}
// cout << "get data returning " << endl;
return retval;
};
@ -3401,12 +3410,13 @@ int* slsDetector::readAll(){
while ((retval=getDataFromDetector())){
i++;
#ifdef VERBOSE
//#ifdef VERBOSE
std::cout<< i << std::endl;
//#else
//std::cout << "-" << flush ;
#endif
//#endif
dataQueue.push(retval);
std::cout<< "pushed" << std::endl;
}
controlSocket->Disconnect();
}
@ -4097,6 +4107,9 @@ int slsDetector::setDynamicRange(int n){
#endif
if (n==24)
n=32;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -4121,8 +4134,15 @@ int slsDetector::setDynamicRange(int n){
if (ret!=FAIL && retval>0) {
/* checking the number of probes to chose the data size */
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8;
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
thisDetector->nChip[X]=retval/16;
thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y];
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*retval/8;
}
if(thisDetector->myDetectorType==MYTHEN){
if (thisDetector->timerValue[PROBES_NUMBER]!=0)
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
@ -4135,10 +4155,10 @@ int slsDetector::setDynamicRange(int n){
thisDetector->dynamicRange=retval;
#ifdef VERBOSE
//#ifdef VERBOSE
std::cout<< "Dynamic range set to "<< thisDetector->dynamicRange << std::endl;
std::cout<< "Data bytes "<< thisDetector->dataBytes << std::endl;
#endif
//#endif
}
@ -4368,11 +4388,14 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
double* slsDetector::decodeData(int *datain, double *fdata) {
double *dataout;
if (fdata)
if (fdata) {
dataout=fdata;
else
// printf("not allocating fdata!\n");
}
else {
dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
// printf("allocating fdata!\n");
}
const int bytesize=8;
int ival=0;

View File

@ -204,11 +204,11 @@ class slsDetectorActions : public virtual slsDetectorBase
*/
virtual int setAllTrimbits(int val, int imod=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual detectorType getDetectorsType(int pos=-1)=0;
/* /\** returns the detector type */
/* \param pos position in the multi detector structure (is -1 returns type of detector with id -1) */
/* \returns type */
/* *\/ */
/* virtual detectorType getDetectorsType(int pos=-1)=0; */
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0;
virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0;

View File

@ -77,6 +77,12 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
/** virtual destructor */
virtual ~slsDetectorBase(){};
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual detectorType getDetectorsType(int pos=-1)=0;
string getDetectorDeveloper(){return string("PSI");};
// protected:

View File

@ -828,6 +828,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
descrToFuncMap[i].m_pFuncName="adcpipeline"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
/* settings dump/retrieve */
descrToFuncMap[i].m_pFuncName="config";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration;
@ -3939,6 +3946,8 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) {
index=ADC_CLOCK;
else if (cmd=="adcphase")
index=ADC_PHASE;
else if (cmd=="adcpipeline")
index=ADC_PIPELINE;
else
return string("could not decode speed variable ")+cmd;

View File

@ -75,6 +75,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
// int getPositions(double *pos=NULL){return angularConversion::getPositions(pos);};
using slsDetectorBase::setFlatFieldCorrection;
using slsDetectorBase::getDetectorsType;
using postProcessing::setBadChannelCorrection;
int enableFlatFieldCorrection(int i=-1) {if (i>0) setFlatFieldCorrectionFile("default"); else if (i==0) setFlatFieldCorrectionFile(""); return getFlatFieldCorrection();};
@ -126,12 +127,6 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual string setHostname(const char* name, int pos=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual detectorType getDetectorsType(int pos=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type

View File

@ -21,6 +21,11 @@ string fileIO::createFileName() {
frameIndex, \
detIndex \
);
if (getDetectorsType()==JUNGFRAUCTB) {
nBytes=2*getTotalNumberOfChannels();
} else
nBytes=getDataBytes();
return currentFileName;
}
@ -86,8 +91,6 @@ int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){
int fileIO::writeDataFile(void *data, int iframe) {
// cout << "fileIO writeDataFile" << endl;
if (iframe<0)
iframe=frameIndex;
@ -100,7 +103,8 @@ int fileIO::writeDataFile(void *data, int iframe) {
}
if (filefd){
fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data);
// fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data);
fileIOStatic::writeBinaryDataFile(filefd,nBytes, data);
iframe++;
}

View File

@ -319,6 +319,8 @@ yes */
// int fformat;
int nBytes;
};
#endif

View File

@ -412,6 +412,7 @@ class fileIOStatic {
};
static int writeBinaryDataFile(FILE *sfilefd, size_t nbytes, void *data){ \
// cout << "bin " << sfilefd << " " << nbytes << " " << data << endl;
fwrite(data, 1, nbytes, sfilefd); \
return slsDetectorDefs::OK; \
};

View File

@ -9,17 +9,17 @@
//#define VERBOSE
static void* startProcessData(void *n){\
postProcessing *myDet=(postProcessing*)n;\
myDet->processData(1);\
pthread_exit(NULL);\
static void* startProcessData(void *n){
postProcessing *myDet=(postProcessing*)n;
myDet->processData(1);
pthread_exit(NULL);
};
static void* startProcessDataNoDelete(void *n){\
postProcessing *myDet=(postProcessing*)n;\
myDet->processData(0);\
pthread_exit(NULL);\
static void* startProcessDataNoDelete(void *n){
postProcessing *myDet=(postProcessing*)n;
myDet->processData(0);
pthread_exit(NULL);
};
@ -65,7 +65,7 @@ postProcessing::~postProcessing(){
void postProcessing::processFrame(int *myData, int delflag) {
void postProcessing::processFrame(int *myData, int delflag, int jctb) {
string fname;
//double *fdata=NULL;
@ -136,7 +136,7 @@ void postProcessing::processFrame(int *myData, int delflag) {
if (dataReady){
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+string(".raw")).c_str() << " " << getTotalNumberOfChannels() << endl;
// cout << "DATAREADY 1" <<endl;
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, currentFrameIndex, pCallbackArg);
delete thisData;
@ -155,14 +155,15 @@ void postProcessing::processFrame(int *myData, int delflag) {
delete [] myData;
if (fdata)
delete [] fdata;
myData=NULL;
fdata=NULL;
// if (jctb==0) {
delete [] myData;
myData=NULL;
#ifdef VERBOSE
cout << "Pop data queue " << *fileIndex << endl;
#endif
@ -177,7 +178,7 @@ void postProcessing::processFrame(int *myData, int delflag) {
#ifdef VERBOSE
cout << "process frame returning " << endl;
#endif
// }
}
@ -278,7 +279,7 @@ data queue size unlock
if (dataReady) {
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+ext).c_str() << " " << np << endl;
//cout << "ADATREADY 2 " << endl;
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
dataReady(thisData, currentFrameIndex, pCallbackArg);
delete thisData;
@ -398,20 +399,35 @@ void* postProcessing::processData(int delflag) {
queuesize=dataQueueSize();
int *myData;
char *p;
int dum=1;
int nf=1, ii, nch;
int jctb=0;
// if (getDetectorsType()==JUNGFRAUCTB) {
// nch=getTotalNumberOfChannels();
// nf= getDataBytes()/(nch*2);
// cout << "WILL PROCESS " << nf << "SAMPLES AND " << nch <<"CHANNELS PER FRAME!" << endl;
// jctb=1;
// }// else
// // cout << "NOOT A JCTB" << endl;
fdata=NULL;
while(dum | *threadedProcessing) { // ????????????????????????
/* IF THERE ARE DATA PROCESS THEM*/
// cout << "loop" << endl;
while((queuesize=dataQueueSize())>0) {
/** Pop data queue */
#ifdef VERBOSE
cout << "data foun"<< endl<<endl;;
#endif
//#ifdef VERBOSE
cout << "data found"<< endl<<endl;;
//#endif
myData=dataQueueFront(); // get the data from the queue
#ifdef VERBOSE
@ -419,21 +435,35 @@ void* postProcessing::processData(int delflag) {
#endif
if (myData) {
processFrame(myData,delflag);
}
// if (jctb) {
// p=(char*)myData;
// for (ii=0; ii<nf; ii++) {
// processFrame((int*)p,delflag, 1);
// p+=2*nch;
// }
// delete [] myData;
// myData=NULL;
// popDataQueue(); //remove the data from the queue
// } else
processFrame(myData,delflag,0);
#ifdef VERBOSE
cout << "frame processed"<< endl;
#endif
}
}
/** IF detector acquisition is done, let the acquire() thread know to finish up and force join thread */
if(acquiringDone){
sem_post(&sem_queue);
// cout << "Sem posted" << endl;
} //else
// cout << "Sem not posted" << endl;
/* IF THERE ARE NO DATA look if acquisition is finished */
if (checkJoinThread()) {
if (dataQueueSize()==0) {
@ -445,7 +475,10 @@ void* postProcessing::processData(int delflag) {
}
if (fdata) {
cout << "delete fdata "<< endl;
delete [] fdata;
cout << "delete done "<< endl;
}
}
//receiver
@ -539,6 +572,7 @@ void* postProcessing::processData(int delflag) {
fdata = decodeData(receiverData);
delete [] receiverData;
if ((fdata) && (dataReady)){
// cout << "DATAREADY 3" << endl;
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,getTotalNumberOfChannels());
dataReady(thisData, currentfIndex, pCallbackArg);
delete thisData;

View File

@ -165,7 +165,7 @@ s
\returns nothing
*/
void processFrame(int* myData, int delflag);
void processFrame(int* myData, int delflag, int jctb=0);
/** processes the data
\param delflag 0 leaves the data in the final data queue
@ -228,6 +228,7 @@ s
virtual int getNMods()=0;
int GetCurrentPositionIndex(){ pthread_mutex_lock(&mp); int retval=getCurrentPositionIndex(); pthread_mutex_unlock(&mp); return retval;};
void IncrementPositionIndex(){ pthread_mutex_lock(&mp); incrementPositionIndex(); pthread_mutex_unlock(&mp);};