Merge branch 'release'

This commit is contained in:
Dhanya Maliakal
2016-02-25 14:24:45 +01:00
48 changed files with 1981 additions and 1960 deletions

View File

@@ -403,7 +403,13 @@ int sendChip(int file_des, sls_detector_chip *myChip) {
return ts;
}
int sendModule(int file_des, sls_detector_module *myMod) {
return sendModuleGeneral(file_des, myMod, 1);
}
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
int ts=0;
#ifdef VERBOSE
int idac;
@@ -422,8 +428,11 @@ int sendModule(int file_des, sls_detector_module *myMod) {
ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
ts+=sendData(file_des,myMod->dacs,sizeof(myMod->ndac),OTHER);
ts+=sendData(file_des,myMod->adcs,sizeof(myMod->nadc),OTHER);
/*some detectors dont require sending all trimbits etc.*/
if(sendAll){
ts+=sendData(file_des,myMod->chipregs,sizeof(myMod->nchip),OTHER);
ts+=sendData(file_des,myMod->chanregs,sizeof(myMod->nchan),OTHER);
}
ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
@@ -440,6 +449,9 @@ int sendModule(int file_des, sls_detector_module *myMod) {
#ifdef VERBOSE
printf("adcs %d of size %d sent\n",myMod->module, ts);
#endif
/*some detectors dont require sending all trimbits etc.*/
if(sendAll){
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
#ifdef VERBOSE
printf("chips %d of size %d sent\n",myMod->module, ts);
@@ -448,6 +460,8 @@ int sendModule(int file_des, sls_detector_module *myMod) {
#ifdef VERBOSE
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
#endif
}
#ifdef VERBOSE
printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg);
#endif
@@ -507,13 +521,16 @@ int receiveChip(int file_des, sls_detector_chip* myChip) {
return ts;
}
int receiveModule(int file_des, sls_detector_module* myMod) {
return receiveModuleGeneral(file_des,myMod,1);
}
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) {
int ts=0;
dacs_t *dacptr=myMod->dacs;
dacs_t *adcptr=myMod->adcs;
int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs;
int ts=0;
int nChips, nchipold=myMod->nchip, nchipdiff;
int nChans, nchanold=myMod->nchan, nchandiff;
int nDacs, ndold=myMod->ndac, ndacdiff;
@@ -531,8 +548,11 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
ts+=receiveData(file_des,myMod->dacs,sizeof(myMod->ndac),INT32);
ts+=receiveData(file_des,myMod->adcs,sizeof(myMod->nadc),INT32);
/*some detectors dont require sending all trimbits etc.*/
if(receiveAll){
ts+=receiveData(file_des,myMod->chipregs,sizeof(myMod->nchip),INT32);
ts+=receiveData(file_des,myMod->chanregs,sizeof(myMod->nchan),INT32);
}
ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
@@ -585,6 +605,7 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
ts+=receiveData(file_des,myMod->dacs, sizeof(dacs_t)*nDacs,INT32);
#ifdef VERBOSE
printf("dacs received\n");
int id;
for (id=0; id<nDacs; id++)
printf("dac %d val %d\n",id, (int)myMod->dacs[id]);
@@ -613,6 +634,10 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
return FAIL;
}
/*some detectors dont require sending all trimbits etc.*/
if(receiveAll){
if (nchipdiff<=0) {
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
#ifdef VERBOSE
@@ -640,8 +665,10 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
free(chanptr);
return FAIL;
}
}
#ifdef VERBOSE
printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg);
#endif
return ts;
}

View File

@@ -42,9 +42,10 @@ int getServerError(int socketDescriptor);
int sendChannel(int file_des, sls_detector_channel *myChan);
int sendChip(int file_des, sls_detector_chip *myChip);
int sendModule(int file_des, sls_detector_module *myMod);
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll);
int receiveChannel(int file_des, sls_detector_channel *myChan);
int receiveChip(int file_des, sls_detector_chip* myChip);
int receiveModule(int file_des, sls_detector_module* myMod);
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll);
#endif

View File

@@ -56,6 +56,8 @@ using namespace std;
#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL
#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL
#define RATE_CORRECTION_TAU_SUBEXPOSURE 0x0000000000400000ULL
// 0x00000000FFFFFFFFULL
/** @short class returning all error messages for error mask */
@@ -177,6 +179,16 @@ public:
if(slsErrorMask&COULD_NOT_PULSE_CHIP)
retval.append("Could not pulse chip\n");
if(slsErrorMask&COULD_NOT_SET_RATE_CORRECTION)
retval.append("Could not set rate correction\n");
if(slsErrorMask&RATE_CORRECTION_TAU_SUBEXPOSURE)
retval.append("Rate Correction Deactivated: (tau/subexptime) must be less than 0.0015\n");
//------------------------------------------------------ length of message
return retval;
}

View File

@@ -22,7 +22,7 @@
#define HEADERLENGTH 12
#define DEFAULT_SUBFRAME_EXPOSURE_VAL 2621440 /** default value for sub frame value 2.6ms*/
#define MAX_SUBFRAME_EXPOSURE_VAL 0x1FFFFFFF /** 29 bit register for max subframe exposure value */
#define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS 0x1FFFFFFF /** 29 bit register for max subframe exposure value */
/** maximum rois */
#define MAX_ROIS 100
@@ -348,7 +348,8 @@ enum dacIndex {
E_Vcn, /**< eiger */
E_Vis, /**< eiger */
IO_DELAY, /**< eiger io delay */
ADC_VPP /**< adc vpp for jctb */
ADC_VPP, /**< adc vpp for jctb */
HV_NEW /**< new hv index for jungfrau & c */
};
/**
@@ -364,6 +365,11 @@ enum detectorSettings{
MEDIUMGAIN, /**< medium gain settings */
VERYHIGHGAIN, /**< very high gain settings */
LOWNOISE, /**< low noise settings */
DYNAMICHG0, /**< dynamic high gain 0 */
FIXGAIN1, /**< fix gain 1 */
FIXGAIN2, /**< fix gain 2 */
FORCESWITCHG1, /**< force switch gain 1 */
FORCESWITCHG2, /**< force switch gain 2 */
UNDEFINED, /**< undefined or custom settings */
UNINITIALIZED /**< uninitialiazed (status at startup) */
};

View File

@@ -98,7 +98,9 @@ enum {
F_SET_COUNTER_BIT, /** < set/reset counter bit in detector for eiger */
F_PULSE_PIXEL, /** < pulse pixel n number of times in eiger at (x,y) */
F_PULSE_PIXEL_AND_MOVE, /** < pulse pixel n number of times and move relatively by x and y */
F_PULSE_CHIP /** < pulse chip n number of times */
F_PULSE_CHIP, /** < pulse chip n number of times */
F_SET_RATE_CORRECT /** < set/reset rate correction tau */
/* Always append functions hereafter!!! */

View File

@@ -43,11 +43,15 @@ unsigned int Feb_Control_triggerMode; //internal timer, external start,
unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity
unsigned int Feb_Control_subFrameMode;
unsigned int Feb_Control_nimages;
double Feb_Control_exposure_time_in_sec;
int Feb_Control_subframe_exposure_time_in_10nsec;
double Feb_Control_exposure_period_in_sec;
int64_t Feb_Control_RateTable_Tau_in_nsec = -1;
int64_t Feb_Control_RateTable_Subexptime_in_nsec = -1;
unsigned int Feb_Control_trimbit_size;
unsigned int* Feb_Control_last_downloaded_trimbits;
@@ -55,7 +59,11 @@ unsigned int* Feb_Control_last_downloaded_trimbits;
int Feb_Control_module_number;
int Feb_Control_current_index;
int counter_bit = 1;
int Feb_Control_counter_bit = 1;
int Feb_control_master = 0;
unsigned int Feb_Control_rate_correction_table[1024];
double Feb_Control_rate_meas[16384];
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
@@ -134,7 +142,7 @@ unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip)
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value) { return Module_BottomAddressIsValid(mod) &&chip<4 ? (mod->idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
float Module_SetHighVoltage(struct Module* mod,float value) { return Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
float Module_SetHighVoltage(struct Module* mod,float value) { return Feb_control_master ? (mod->high_voltage=value) : -1;}// Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
float Module_GetHighVoltage(struct Module* mod) { return mod->high_voltage;}
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_TopAddressIsValid(mod)) ? (mod->top_dac[i]=value) : -1;}
@@ -166,27 +174,16 @@ void Feb_Control_FebControl(){
int Feb_Control_Init(int master, int top){
int Feb_Control_Init(int master, int top, int module_num){
unsigned int i;
Feb_Control_module_number = 0;
Feb_Control_current_index = 0;
Feb_control_master = master;
//global send
Feb_Control_AddModule1(0,1,0xff,0,1);
Feb_Control_PrintModuleList();
//get module nummber
int res=0;
char hostname[100];
if (gethostname(hostname, sizeof hostname) == 0)
puts(hostname);
else
perror("gethostname");
char *pch;
pch = strtok(hostname,"0");
pch = strtok(NULL,"0");
sscanf(pch,"%d",&res);
Feb_Control_module_number = (res & 0xFF);
Feb_Control_module_number = (module_num & 0xFF);
int serial = !top;
@@ -538,7 +535,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
}
int Feb_Control_CheckSetup(){
int Feb_Control_CheckSetup(int master){
printf("Checking Set up\n");
unsigned int i,j;
int ok = 1;
@@ -556,7 +553,7 @@ int Feb_Control_CheckSetup(){
ok=0;
}
}
if(Module_GetHighVoltage(&modules[i])<0){
if((Feb_control_master) &&(Module_GetHighVoltage(&modules[i])<0)){
cprintf(RED,"Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i]));
ok=0;
}
@@ -709,7 +706,7 @@ int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
unsigned int module_index=0;
unsigned int i;
if(Module_TopAddressIsValid(&modules[module_index])){
if(Feb_control_master){//if(Module_TopAddressIsValid(&modules[module_index])){
if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/
cprintf(RED,"Error could not set high voltage module number %d invalid.\n",module_num);
return 0;
@@ -962,7 +959,9 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
for(l_r=0;l_r<2;l_r++){ // l_r loop
//printf("\nl_r:%d\t\t",l_r);
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
printf("Could not select chips\n");
return 0;
}
@@ -1187,7 +1186,7 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
}
int Feb_Control_Reset(){
int Feb_Control_Reset(){printf("Reset daq\n");
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
cprintf(RED,"Warning: Could not reset daq, no response.\n");
return 0;
@@ -1378,7 +1377,7 @@ int Feb_Control_SetSubFrameExposureTime(int the_subframe_exposure_time_in_10nsec
printf("Sub Frame Exposure time set to: %d\n",Feb_Control_subframe_exposure_time_in_10nsec);
return 1;
}
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec;}
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec*10;}
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec){
Feb_Control_exposure_period_in_sec = the_exposure_period_in_sec;
@@ -1545,7 +1544,7 @@ int Feb_Control_PrepareForAcquisition(){//return 1;
}
int ret=0;
if(counter_bit)
if(Feb_Control_counter_bit)
ret = Feb_Control_ResetChipCompletely();
else
ret = Feb_Control_ResetChipPartially();
@@ -1648,11 +1647,11 @@ int Feb_Control_SaveAllTrimbitsTo(int value){
void Feb_Control_Set_Counter_Bit(int value){
counter_bit = value;
Feb_Control_counter_bit = value;
}
int Feb_Control_Get_Counter_Bit(){
return counter_bit;
return Feb_Control_counter_bit;
}
int Feb_Control_Pulse_Pixel(int npulses, int x, int y){
@@ -1777,8 +1776,8 @@ int Feb_Control_PulseChip(int npulses){
cprintf(RED,"some wait error\n");
}
Feb_Control_SetExternalEnableMode(on,1);
counter_bit = (on?0:1);
printf("counter_bit:%d\n",counter_bit);
Feb_Control_counter_bit = (on?0:1);
printf("Feb_Control_counter_bit:%d\n",Feb_Control_counter_bit);
if(on)
printf("Pulse chip success\n\n");
@@ -1789,10 +1788,174 @@ int Feb_Control_PulseChip(int npulses){
int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;}
//returns -1 if slope is too high
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
unsigned int np = 16384; //max slope 16 * 1024
double b0[1024];
double m[1024];
if(tau_in_sec<0||sub_expure_time_in_sec<0){
printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec);
return 0;
}
printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec);
int i;
for(i=0;i<np;i++)
Feb_Control_rate_meas[i] = i*exp(-i/sub_expure_time_in_sec*tau_in_sec);
/*
b : index/address of block ram/rate correction table
b0 : base in vhdl
m : slope in vhdl
Firmware:
data_in(11..2) -> memory address --> memory
data_in( 1..0) -> lsb
mem_data_out(13.. 0) -> base
mem_data_out(17..14) -> slope
delta = slope*lsb
corr = base+delta
*/
int next_i=0;
b0[0] = 0;
m[0] = 1;
int b;
for(b=1;b<1024;b++){
if(m[b-1]<14.5){
double s=0,sx=0,sy=0,sxx=0,sxy=0;
for(;;next_i++){
if(next_i>=np){
cprintf(RED,"Error: (tau/subexptime) must be < 0.0015 \n");
return -1;
}
double x = Feb_Control_rate_meas[next_i] - b*4;
double y = next_i;
/*printf("Start Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
if(x < -0.5) continue;
if(x > 3.5) break;
s += 1;
sx += x;
sy += y;
sxx += x*x;
sxy += x*y;
/*printf("End Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
}
double delta = s*sxx - sx*sx;
b0[b] = (sxx*sy - sx*sxy)/delta;
m[b] = (s*sxy - sx*sy) /delta;
if(m[b]<0||m[b]>15)
m[b]=15;
/*printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
}else{
b0[b] = b0[b-1] + 4*m[b-1];
m[b] = m[b-1];
/*printf("else\n");*/
}
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
/*printf("After Loop 4*b: %d\tbase:%d\tslope:%d\n",4*b, (int)(b0[b]+0.5), (int)(m[b]+0.5) );*/
}
if(Feb_Control_SetRateCorrectionTable(Feb_Control_rate_correction_table)){
Feb_Control_RateTable_Tau_in_nsec = tau_in_Nsec;
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
return 1;
}else{
Feb_Control_RateTable_Tau_in_nsec = -1;
Feb_Control_RateTable_Subexptime_in_nsec = -1;
return 0;
}
}
int Feb_Control_SetRateCorrectionTable(unsigned int *table){
if(!table){
printf("Error: could not set rate correction table, point is zero.\n");
Feb_Control_SetRateCorrectionVariable(0);
return 0;
}
printf("Setting rate correction table. %d %d %d %d ....\n",
table[0],table[1],table[2],table[3]);
//was added otherwise after an acquire, startdaqonlywatiforfinish waits forever
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY)){
cprintf(RED,"Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n");
return 0;
}
printf("daq reset completely\n");
if(Module_TopAddressIsValid(&modules[1])){
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
return 0;
}
}else{
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
return 0;
}
}
return 1;
}
int Feb_Control_GetRateCorrectionVariable(){ return (Feb_Control_subFrameMode&DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION);}
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction){
if(activate_rate_correction){
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
printf("Rate correction activated. Note: the rate correction applied only when run in auto summing mode.\n");
}else{
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
printf("Rate correction deactivated.\n");
}
}
int Feb_Control_PrintCorrectedValues(){
int i;
int delta, slope, base, lsb, corr;
for (i=0; i < 4096; i++){
lsb = i&3;
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
delta = slope*lsb;
corr = delta+base;
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
}
return 1;
}

View File

@@ -111,7 +111,7 @@ int Feb_Control_GetModuleNumber();
void Feb_Control_FebControl();
int Feb_Control_Init(int master, int top);
int Feb_Control_Init(int master, int top, int module_num);
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
int Feb_Control_CheckSetup();
@@ -184,5 +184,12 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_ClockRowClock(unsigned int ntimes);
int Feb_Control_PulseChip(int npulses);
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec();
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
int Feb_Control_GetRateCorrectionVariable();
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
int Feb_Control_PrintCorrectedValues();
#endif

View File

@@ -32,7 +32,7 @@
/*int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons=0, unsigned int* wait_on_addresses=0);*/
int Feb_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
//mem_num is 0 for trimbit BRAM and 1 for rate correction BRAM
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);

View File

@@ -0,0 +1,3 @@
mv bin/eigerDetectorServer bin/$2
git rm bin/$1
git add bin/$2

View File

@@ -51,9 +51,24 @@ unsigned int nimages_per_request=1;
int on_dst=0;
int dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//char Module_dac_names[16][10]= {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};;
int default_dac_values[16] = {0,2480,3300,1400,4000,2556,1000,1000,4000,1000,1000,1000,1000,200,2000,1550};
int default_dac_values[16] = {
0, //SvP
2480, //Vtr
3300, //Vrf
1400, //Vrs
4000, //SvN
2556, //Vtgstv
1000, //Vcmp_ll
1000, //Vcmp_lr
4000, //cal
1000, //Vcmp_rl
1100, //rxb_rb
1100, //rxb_lb
1000, //Vcmp_rr
200, //Vcp
2000, //Vcn
1550 //Vis
};
int default_gain_values[3] = {517000,517000,517000};
int default_offset_values[3] = {3851000,3851000,3851000};
@@ -125,7 +140,7 @@ int initDetector(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top);
Feb_Control_Init(master,top,getDetectorNumber());
printf("FEB Initialization done\n");
Beb_Beb();
printf("BEB Initialization done\n");
@@ -145,10 +160,10 @@ int initDetector(){
setReadOutFlags(NONPARALLEL);
setSpeed(0,1);//clk_devider,half speed
setHighVolage(0,0);
setIODelay(675,0);
setIODelay(650,0);
setTiming(AUTO_TIMING);
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
//SetRateCorrection(0); //deactivate rate correction
setRateCorrection(0); //deactivate rate correction
int enable[2] = {0,1};
setExternalGating(enable);//disable external gating
Feb_Control_SetInTestModeVariable(0);
@@ -166,7 +181,7 @@ int initDetectorStop(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top);
Feb_Control_Init(master,top,getDetectorNumber());
printf("FEB Initialization done\n");
/* Beb_Beb(-1);
printf("BEB constructor done\n");*/
@@ -279,6 +294,9 @@ u_int64_t getDetectorMAC() {
pch = strtok (NULL, ":");
}
sscanf(mac,"%llx",&res);
//increment by 1 for 10g
if(send_to_ten_gig)
res++;
//printf("mac:%llx\n",res);
return res;
@@ -471,9 +489,54 @@ int pulseChip(int n){
return OK;
}
int setRateCorrection(int64_t custom_tau_in_nsec){//in nanosec (will never be -1)
//deactivating rate correction
if(custom_tau_in_nsec==0){
Feb_Control_SetRateCorrectionVariable(0);
return 0;
}
int64_t tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
int64_t subexp_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
//same setting
if((tau_in_nsec == custom_tau_in_nsec) && (subexp_in_nsec == Feb_Control_GetSubFrameExposureTime())){
printf("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
tau_in_nsec,subexp_in_nsec);
}
//different setting, calculate table
else{
int ret = Feb_Control_SetRateCorrectionTau(custom_tau_in_nsec);
if(ret<=0){
cprintf(RED,"Rate correction failed. Deactivating rate correction\n");
Feb_Control_SetRateCorrectionVariable(0);
return ret;//-1 is for tau/subexptime error, 0 for all other errors
}
}
//activating rate correction
Feb_Control_SetRateCorrectionVariable(1);
#ifdef VERBOSE
Feb_Control_PrintCorrectedValues();
#endif
return Feb_Control_Get_RateTable_Tau_in_nsec();
}
int getRateCorrectionEnable(){
return Feb_Control_GetRateCorrectionVariable();
}
int getDefaultSettingsTau_in_nsec(){
switch(thisSettings){
case STANDARD: return STANDARD_TAU;
case HIGHGAIN: return HIGHGAIN_TAU;
case LOWGAIN: return LOWGAIN_TAU;
default: return -1;
}
}
int setModule(sls_detector_module myMod, int* gain, int* offset){
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){
int retval[2];
int i;
@@ -497,6 +560,12 @@ int setModule(sls_detector_module myMod, int* gain, int* offset){
printf("offset[%d]:%d\n",i,detectorOffset[i]);
}else cprintf(RED,"offset not set\n");
}
if(setIODelay(*delay, -1)!= (*delay)){
cprintf(RED,"could not set iodelay %d\n",*delay);
return FAIL;
}
//copy module locally
if (detectorModules)
copyModule(detectorModules,&myMod);
@@ -761,7 +830,7 @@ int64_t setTimer(enum timerIndex ind, int64_t val){
printf(" Setting sub exp time: %dns\n",(int)val/10);
Feb_Control_SetSubFrameExposureTime(val/10);
}
return (Feb_Control_GetSubFrameExposureTime()*10);
return (Feb_Control_GetSubFrameExposureTime());
case FRAME_PERIOD:
@@ -911,8 +980,6 @@ int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival){
//only for 1Gbe
if(!send_to_ten_gig){
if (detectormacadd != getDetectorMAC()){
printf("*************************************************\n");
printf("WARNING: actual detector mac address %llx does not match the one from client %llx\n",getDetectorMAC(),detectormacadd);
@@ -920,6 +987,8 @@ int configureMAC(int ipad, long long int macad, long long int detectormacadd, in
printf("WARNING: Matched detectormac to the hardware mac now\n");
printf("*************************************************\n");
}
//only for 1Gbe
if(!send_to_ten_gig){
if (detipad != getDetectorIP()){
printf("*************************************************\n");
printf("WARNING: actual detector ip address %x does not match the one from client %x\n",getDetectorIP(),detipad);

View File

@@ -40,4 +40,12 @@
enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD};
enum defaultTauValues{
HIGHGAIN_TAU=410,
STANDARD_TAU=290,
LOWGAIN_TAU=180};
#endif /* SLSDETECTORSERVER_DEFS_H_ */

View File

@@ -725,9 +725,9 @@ int setSettings(int i, int imod) {
}
}
thisSettings=isett;
#ifdef VERBOSE
//#ifdef VERBOSE
printf("detector settings are %d\n",thisSettings);
#endif
//#endif
return thisSettings;
}

View File

@@ -9,14 +9,14 @@ CC = $(CROSS)gcc
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER
PROGS= jungfrauDetectorServer
PROGS= jungfrauDetectorServerTest
INSTDIR= /tftpboot
INSTMODE= 0777
BINS = testlib_sharedlibc
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c sharedmemory.c
OBJS = $(SRCS:%.c=%.o)
@@ -27,6 +27,11 @@ test: clean jungfrauADCTEst
boot: $(OBJS)
jungfrauDetectorServerTest: $(OBJS)
echo $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
jungfrauDetectorServer: $(OBJS)
echo $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)

View File

@@ -0,0 +1 @@
/afs/psi.ch/project/sls_det_software/dhanya_softwareDevelopment/mySoft/slsDetectorsPackage/slsReceiverSoftware/include/ansi.h

View File

@@ -1,6 +1,7 @@
//#define TESTADC
#define TESTADC1
//#define TIMEDBG
#include "server_defs.h"
#include "firmware_funcs.h"
@@ -64,7 +65,8 @@ struct timeval tss,tse,tsss; //for timing
//for memory mapping
u_int64_t CSP0BASE;
u_int32_t CSP0BASE;
FILE *debugfp, *datafp;
@@ -96,7 +98,11 @@ int phase_shift=0;//DEFAULT_PHASE_SHIFT;
int ipPacketSize=DEFAULT_IP_PACKETSIZE;
int udpPacketSize=DEFAULT_UDP_PACKETSIZE;
#ifndef NEW_PLL_RECONFIG
u_int32_t clkDivider[2]={32,16};
#else
u_int32_t clkDivider[2]={40,20};
#endif
int32_t clkPhase[2]={0,0};
u_int32_t adcDisableMask=0;
@@ -109,22 +115,20 @@ enum externalSignalFlag signals[4]={EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF, EXT_
int withGotthard = 0;
#ifdef MCB_FUNCS
extern const int nChans;
extern const int nChips;
//extern const int nDacs;
//extern const int nAdcs;
#endif
#ifndef MCB_FUNCS
const int nChans=NCHAN;
const int nChips=NCHIP;
const int nDacs=NDAC;
const int nAdcs=NADC;
#endif
/**is not const because this value will change after initDetector, is removed from mcb_funcs.c cuz its not used anywhere
* why is this used anywhere instead of macro*/
int nChans=NCHAN;
int nChips=NCHIP;
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;
int mapCSP0(void) {
printf("Mapping memory\n");
@@ -155,8 +159,8 @@ int mapCSP0(void) {
return FAIL;
}
#endif
printf("CSPObase is 0x%x \n",CSP0BASE);
printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
printf("CSPObase is 0x%08x \n",CSP0BASE);
printf("CSPOBASE=from %08x to %08x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
u_int32_t address;
address = FIFO_DATA_REG;//_OFF;
@@ -383,7 +387,6 @@ u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig) {
u_int32_t getPllReconfigReg(u_int32_t reg, int trig) {
int i;
u_int32_t val=reg<<PLL_CNTR_ADDR_OFF;
u_int32_t vv;
@@ -431,17 +434,17 @@ 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;
int32_t phase=0, inv=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);
#ifndef NEW_PLL_RECONFIG
printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,1,0);
// usleep(10000);
#endif
if (i<2) {
@@ -498,15 +501,20 @@ void configurePll(int i) {
// printf("Phase, val: %08x\n", val);
setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0
val=phase | (2<<16);// | (inv<<21);
#ifndef NEW_PLL_RECONFIG
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,1,0);
// usleep(10000);
#endif
printf("**************** phase word %08x\n",val);
val=phase | (2<<16);// | (inv<<21);
// printf("Phase, val: %08x\n", val);
setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0
}
@@ -514,12 +522,13 @@ void configurePll(int i) {
}
#ifndef NEW_PLL_RECONFIG
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);
#endif
// printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,0,0);
usleep(10000);
if (i<2) {
@@ -543,13 +552,10 @@ void configurePll(int i) {
u_int32_t setClockDivider(int d, int ic) {
u_int32_t l=0x0c;
u_int32_t h=0x0d;
u_int32_t val;
int i;
//u_int32_t l=0x0c;
//u_int32_t h=0x0d;
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);
@@ -581,16 +587,23 @@ u_int32_t setClockDivider(int d, int ic) {
int phaseStep(int st){
int i;
if (st>65535 || st<-65535)
return clkPhase[0];
#ifdef NEW_PLL_RECONFIG
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);
printf("phase %d\n", st);
clkPhase[1]=st;
#else
clkPhase[1]=st-clkPhase[0];
#endif
printf("phase %d\n", clkPhase[1] );
configurePll(2);
clkPhase[0]=st;
return clkPhase[0];
@@ -1128,16 +1141,25 @@ u_int32_t testFpga(void) {
// for fpga test
u_int32_t testRAM(void) {
int result=OK;
int i=0;
printf("TestRAM not implemented\n");
/* int i=0;
allocateRAM();
// while(i<100000) {
memcpy(ram_values, values, dataBytes);
printf ("Testing RAM:\t%d: copied fifo %x to memory %x size %d\n",i++, (unsigned int)(values), (unsigned int)(ram_values), dataBytes);
// }
*
*/
return result;
}
int getNModBoard() {
if(myDetectorType == JUNGFRAU)
return 1;
else
return 32;//nModX;
}
@@ -1211,7 +1233,7 @@ int64_t setFrames(int64_t value){
}
int64_t getFrames(){
printf("gf");
/*printf("gf");*/
return get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG);
}
@@ -1238,7 +1260,7 @@ int64_t setPeriod(int64_t value){
/* time is in ns */
if (value!=-1) {
// value*=(1E-9*CLK_FREQ);
value*=(1E-3*clkDivider[0]);
value*=(1E-3*clkDivider[1]);
}
if (value%2==0) {
@@ -1261,7 +1283,7 @@ int64_t getPeriod(){
int64_t setDelay(int64_t value){
/* time is in ns */
if (value!=-1) {
value*=(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
value*=(1E-3*clkDivider[1]);//(1E-9*CLK_FREQ);
}
return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ);
}
@@ -1337,10 +1359,15 @@ int64_t getFramesFromStart(){
ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
if(myDetectorType == JUNGFRAU)
cprintf(RED,"ROI Not implemented for Jungfrau yet\n");
return NULL;
ROI retval[MAX_ROIS];
int i, ich;
adcDisableMask=0xfffffffff;
adcDisableMask=0xfffffffff; /*warning: integer constant is too large for long type,warning: large integer implicitly truncated to unsigned type*/
printf("Setting ROI\n");
if (nroi>=0) {
@@ -1350,7 +1377,7 @@ ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
for (i=0; i<nroi; i++) {
printf("iroi: %d - %d %d %d %d\n",i, arg[i].xmin, arg[i].xmax, arg[i].ymin, arg[i].ymax);
for (ich=arg[i].xmin; ich<=arg[i].xmax; ich++) {
if (ich>=0 && ich<NCHAN)
if (ich>=0 && ich<N_CHAN)
adcDisableMask&=~(1<<ich);
else
break;
@@ -1369,7 +1396,7 @@ ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
*retvalsize=0;
retval[0].xmin=0;
retval[0].xmax=0;
for (ich=0 ; ich<NCHAN ; ich++) {
for (ich=0 ; ich<N_CHAN ; ich++) {
if ((~adcDisableMask)&(1<<ich)) {
if (ich==0) {
*retvalsize+=1;
@@ -1393,11 +1420,16 @@ ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) {
}
}
getDynamicRange();
return retval;
return retval;/*warning: function returns address of local variable*/
}
int loadImage(int index, short int ImageVals[]){
printf("loadImage Not implemented yet\n");
/*
u_int32_t address;
switch (index) {
case DARK_IMAGE :
@@ -1418,6 +1450,8 @@ int loadImage(int index, short int ImageVals[]){
#ifdef VERBOSE
printf("\nLoaded x%08x address with image of index %d\n",(unsigned int)(ptr),index);
#endif
*/
return OK;
}
@@ -1524,88 +1558,78 @@ int getTemperature(int tempSensor, int imod){
int initHighVoltage(int val, int imod){
printf("*******SetHV: Doing nothing - still to be implemented!\n");
/* #ifdef VERBOSE */
/* printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val); */
/* #endif */
/* volatile u_int32_t addr=HV_REG; */
/* int writeVal,writeVal2; */
/* switch(val){ */
/* case -1: break; */
/* case 0: writeVal=0x0; writeVal2=0x0; break; */
/* case 90: writeVal=0x0; writeVal2=0x1; break; */
/* case 110:writeVal=0x2; writeVal2=0x3; break; */
/* case 120:writeVal=0x4; writeVal2=0x5; break; */
/* case 150:writeVal=0x6; writeVal2=0x7; break; */
/* case 180:writeVal=0x8; writeVal2=0x9; break; */
/* case 200:writeVal=0xA; writeVal2=0xB; break; */
/* default :printf("Invalid voltage\n");return -2;break; */
/* } */
/* //to set value */
/* if(val!=-1){ */
/* //set value to converted value */
/* bus_w(addr,writeVal); */
/* bus_w(addr,writeVal2); */
/* #ifdef VERBOSE */
/* printf("Value sent is %d and then %d\n",writeVal,writeVal2); */
/* #endif */
/* } */
/* //read value and return the converted value */
/* val=bus_r(addr); */
/* #ifdef VERBOSE */
/* printf("Value read from reg is %d\n",val); */
/* #endif */
/* switch(val){ */
/* case 0x0:val=0;break; */
/* case 0x1:val=90;break; */
/* case 0x3:val=110;break; */
/* case 0x5:val=120;break; */
/* case 0x7:val=150;break; */
/* case 0x9:val=180;break; */
/* case 0xB:val=200;break; */
/* default:printf("Weird value read:%d\n",val);return -3;break; */
/* } */
/* #ifdef VERBOSE */
/* printf("High voltage of module:%d is %d\n",imod,val); */
/* #endif */
return val;
u_int32_t offw,codata;
u_int16_t valw, dacvalue;
int iru,i,ddx,csdx,cdx;
float alpha=0.55, fval=val;
if (val>=0) {
if (val<60) {
dacvalue=0;
val=60;
} else if (val>=200) {
dacvalue=0x1;
val=200;
} else {
dacvalue=1.+(200.-val)/alpha;
val=200.-(dacvalue-1)*alpha;
}
printf ("****************************** setting val %d, dacval %d\n",val, dacvalue);
offw=DAC_REG;
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=(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);
}
return bus_r(HV_REG);
// return val;
}
int initConfGain(int isettings,int val,int imod){
int retval;
u_int32_t addr=GAIN_REG;
if(val!=-1){
#ifdef VERBOSE
printf("Setting Gain of module:%d with val:%d\n",imod,val);
#endif
bus_w(addr,((val<<GAIN_OFFSET)|(bus_r(addr)&~GAIN_MASK)));
}
retval=(bus_r(addr)&GAIN_MASK);
#ifdef VERBOSE
printf("Value read from Gain reg is %d\n",retval);
#endif
if((val!=-1)&&(retval!=val))
return -1;
u_int32_t addr=CONFGAIN_REG;
if(isettings!=-1){
#ifdef VERBOSE
printf("Writing Settings of module:%d with val:%d\n",imod,isettings);
printf("Setting Gain of module:%d with val:%d\n",imod,val);
#endif
bus_w(addr,((isettings<<SETTINGS_OFFSET)|(bus_r(addr)&~SETTINGS_MASK)));
bus_w(addr,val);
}
retval=((bus_r(addr)&SETTINGS_MASK)>>SETTINGS_OFFSET);
retval=(bus_r(addr));
#ifdef VERBOSE
printf("Settings read from reg is %d\n",retval);
printf("Value read from Gain reg is %d\n",retval);
#endif
if((isettings!=-1)&&(retval!=isettings)){
printf("\n\nSettings r\n\n");
return -1;
}
return retval;
}
@@ -1637,8 +1661,8 @@ int setADC(int adc){
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = NCHIP;
nchans = NCHANS;
nchips = N_CHIP;
nchans = N_CHANS;
mask = ACTIVE_ADC_MASK;
}/*
//with moench module 1 adc -- NOT IMPLEMENTED
@@ -1667,21 +1691,15 @@ int setADC(int adc){
}
int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int sourceip,int ival,uint32_t destport) {
//int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int udpport){
uint32_t sourceport = 0x7e9a; // 0xE185;
//setheader(0xF452142F3200,0x00ad29ae39fd,0x0a000264,0x0A00020d ,0x8436, 0x7e9a);
long int calcChecksum(int sourceip, int destip) {
/* void setheader(uint64_t destmac, uint64_t sourcemac, uint32_t destip, uint32_t sourceip, uint32_t destport, */
/* uint32_t sourceport){ */
ip_header ip;
int count;
unsigned short *addr;
long int sum = 0;
long int checksum;
volatile u_int32_t conf= bus_r(CONFIG_REG);
ip.ip_ver = 0x4;
ip.ip_ihl = 0x5;
@@ -1698,7 +1716,7 @@ ip.ip_destip = destip;
count=sizeof(ip);
addr=&(ip);
addr=&(ip); /* warning: assignment from incompatible pointer type */
while( count > 1 ) {
sum += *addr++;
count -= 2;
@@ -1707,9 +1725,63 @@ ip.ip_destip = destip;
while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits
checksum = (~sum)&0xffff;
printf("IP checksum is 0x%x\n",checksum);
printf("IP checksum is 0x%lx\n",checksum);
return checksum;
}
#ifdef NEW_GBE_INTERFACE
int writeGbeReg(int ivar, uint32_t val, int addr, int interface) {
/* #define GBE_CTRL_WSTROBE 0 */
/* #define GBE_CTRL_VAR_OFFSET 16 */
/* #define GBE_CTRL_VAR_MASK 0XF */
/* #define GBE_CTRL_RAMADDR_OFFSET 24 */
/* #define GBE_CTRL_RAMADDR_MASK 0X3F */
/* #define GBE_CTRL_INTERFACE 23 */
uint32_t ctrl=((ivar&GBE_CTRL_VAR_MASK)<<GBE_CTRL_VAR_OFFSET)|((addr&GBE_CTRL_RAMADDR_MASK)<<GBE_CTRL_RAMADDR_OFFSET)| (interface<<GBE_CTRL_INTERFACE);
bus_w(GBE_CNTRL_REG,ctrl);
bus_w(GBE_PARAM_REG,val);
bus_w(GBE_CNTRL_REG,ctrl|(1<<GBE_CTRL_WSTROBE));
usleep(100);
bus_w(GBE_CNTRL_REG,ctrl);
}
#endif
int configureInterface(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int sourceip,int ival,uint32_t destport, uint32_t sourceport, int interface) {
//int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int udpport){
volatile u_int32_t conf= bus_r(CONFIG_REG);
long int checksum=calcChecksum(sourceip, destip);
#ifdef NEW_GBE_INTERFACE
printf("Configure interface %d\n",interface);
const int nvar=12;
uint32_t vals[nvar];
int ivar;
int addr=0;
vals[RX_UDP_IP_ADDR]=destip;
vals[RX_UDP_PORTS_ADDR]=destport;
vals[RX_UDP_MAC_L_ADDR]=(destmac)&0xFFFFFFFF;
vals[RX_UDP_MAC_H_ADDR]=(destmac>>32)&0xFFFFFFFF;
vals[IPCHECKSUM_ADDR]=checksum;
vals[GBE_DELAY_ADDR]=0;
vals[GBE_RESERVED1_ADDR]=sourceport;
vals[GBE_RESERVED2_ADDR]=interface;
vals[DETECTOR_MAC_L_ADDR]=(sourcemac)&0xFFFFFFFF;
vals[DETECTOR_MAC_H_ADDR]=(sourcemac>>32)&0xFFFFFFFF;
vals[DETECTOR_IP_ADDR]=sourceip;
for (ivar=0; ivar<nvar; ivar++) {
writeGbeReg(ivar, vals[ivar], addr, interface);
}
#else
bus_w(DETECTORIP_AREG,sourceip);//detectorip_AReg_c
bus_w(RX_UDP_AREG,destip);//rx_udpip_AReg_c
@@ -1717,9 +1789,12 @@ ip.ip_destip = destip;
bus_w(RX_UDPMACL_AREG,(destmac)&0xFFFFFFFF);//rx_udpmacL_AReg_c
bus_w(DETECTORMACH_AREG,(sourcemac>>32)&0xFFFFFFFF);//detectormacH_AReg_c
bus_w(DETECTORMACL_AREG,(sourcemac)&0xFFFFFFFF);//detectormacL_AReg_c
bus_w(UDPPORTS_AREG,((destport&0xFFFF)<<16)+(sourceport&0xFFFF));//udpports_AReg_c
bus_w(UDPPORTS_AREG,((sourceport&0xFFFF)<<16)+(destport&0xFFFF));//udpports_AReg_c
bus_w(IPCHKSUM_AREG,(checksum&0xFFFF));//ipchksum_AReg_c
#endif
bus_w(CONTROL_REG,GB10_RESET_BIT);
sleep(1);
bus_w(CONTROL_REG,0);
@@ -1727,198 +1802,51 @@ ip.ip_destip = destip;
bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT);
printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG));
return 0; //any value doesnt matter - dhanya
}
int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int sourceip,int ival,uint32_t destport) {
//int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int udpport){
uint32_t sourceport = 0x7e9a; // 0xE185;
int interface=0;
int ngb;
volatile u_int32_t conf= bus_r(CONFIG_REG);
#ifdef NEW_GBE_INTERFACE
ngb=2;
printf("--------- New XGB interface\n");
#else
ngb=1;
printf("********* Old XGB interface\n");
#endif
for (interface=0; interface <ngb; interface++)
configureInterface(destip, destmac, sourcemac+interface, sourceip+interface, ival, destport+interface, sourceport+interface, interface);
bus_w(CONTROL_REG,GB10_RESET_BIT);
bus_w(CONTROL_REG,0);
usleep(10000);
bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT);
printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG));
return;
/* } */
/* #ifdef DDEBUG */
/* printf("Chip of Intrst Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); */
/* printf("IP Packet Size:%d\n",ipPacketSize); */
/* printf("UDP Packet Size:%d\n",udpPacketSize); */
/* #endif */
/* //configuring mac */
/* u_int32_t addrr=MULTI_PURPOSE_REG; */
/* u_int32_t offset=ENET_CONF_REG, offset2=TSE_CONF_REG; */
/* mac_conf *mac_conf_regs; */
/* tse_conf *tse_conf_regs; */
/* long int sum = 0; */
/* long int checksum; */
/* int count,val; */
/* unsigned short *addr; */
/* mac_conf_regs=(mac_conf*)(CSP0BASE+offset*2); */
/* tse_conf_regs=(tse_conf*)(CSP0BASE+offset2*2); */
/* #ifdef DDEBUG */
/* printf("***Configuring MAC*** \n"); */
/* #endif */
/* if(ival) */
/* bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset) */
/* else */
/* bus_w(addrr,RESET_BIT); //0x080,reset mac (reset) */
/* val=bus_r(addrr); */
/* #ifdef VERBOSE */
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
/* #endif */
/* // if(val!=0x080) return -1; */
/* usleep(500000); */
/* if(ival) */
/* bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak) */
/* else */
/* bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x840,write shadow regs(enet reset,write bak) */
/* val=bus_r(addrr); */
/* #ifdef VERBOSE */
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
/* #endif */
/* // if(val!=0x840) return -1; */
/* if(ival) */
/* bus_w(addrr,(ENET_RESETN_BIT|DIGITAL_TEST_BIT)); //0x800,nreset phy(enet reset) */
/* else */
/* bus_w(addrr,ENET_RESETN_BIT); //0x800,nreset phy(enet reset) */
/* val=bus_r(addrr); */
/* #ifdef VERBOSE */
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
/* #endif */
/* // if(val!=0x800) return -1; */
/* mac_conf_regs->mac.mac_dest_mac1 =((macad>>(8*5))&0xFF);// 0x00; //pc7060 */
/* mac_conf_regs->mac.mac_dest_mac2 =((macad>>(8*4))&0xFF);// 0x19; //pc7060 */
/* mac_conf_regs->mac.mac_dest_mac3 =((macad>>(8*3))&0xFF);// 0x99; //pc7060 */
/* mac_conf_regs->mac.mac_dest_mac4 =((macad>>(8*2))&0xFF);// 0x24; //pc7060 */
/* mac_conf_regs->mac.mac_dest_mac5 =((macad>>(8*1))&0xFF);// 0xEB; //pc7060 */
/* mac_conf_regs->mac.mac_dest_mac6 =((macad>>(8*0))&0xFF);// 0xEE; //pc7060 */
/* /\* */
/* mac_conf_regs->mac.mac_src_mac1 = 0x00; */
/* mac_conf_regs->mac.mac_src_mac2 = 0xAA; */
/* mac_conf_regs->mac.mac_src_mac3 = 0xBB; */
/* mac_conf_regs->mac.mac_src_mac4 = 0xCC; */
/* mac_conf_regs->mac.mac_src_mac5 = 0xDD; */
/* mac_conf_regs->mac.mac_src_mac6 = 0xEE; */
/* *\/ */
/* mac_conf_regs->mac.mac_src_mac1 =((detectormacad>>(8*5))&0xFF); */
/* mac_conf_regs->mac.mac_src_mac2 =((detectormacad>>(8*4))&0xFF); */
/* mac_conf_regs->mac.mac_src_mac3 =((detectormacad>>(8*3))&0xFF); */
/* mac_conf_regs->mac.mac_src_mac4 =((detectormacad>>(8*2))&0xFF); */
/* mac_conf_regs->mac.mac_src_mac5 =((detectormacad>>(8*1))&0xFF); */
/* mac_conf_regs->mac.mac_src_mac6 =((detectormacad>>(8*0))&0xFF); */
/* mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4 */
/* mac_conf_regs->ip.ip_ver = 0x4; */
/* mac_conf_regs->ip.ip_ihl = 0x5; */
/* mac_conf_regs->ip.ip_tos = 0x0; */
/* mac_conf_regs->ip.ip_len = ipPacketSize;//0x0522; // was 0x0526; */
/* mac_conf_regs->ip.ip_ident = 0x0000; */
/* mac_conf_regs->ip.ip_flag = 0x2; */
/* mac_conf_regs->ip.ip_offset = 0x00; */
/* mac_conf_regs->ip.ip_ttl = 0x70; */
/* mac_conf_regs->ip.ip_protocol = 0x11; */
/* mac_conf_regs->ip.ip_chksum = 0x0000 ; //6E42 now is automatically computed */
/* mac_conf_regs->ip.ip_sourceip = detipad; //0x8181CA2E;129.129.202.46 */
/* mac_conf_regs->ip.ip_destip = ipad; //CA57 */
/* //#ifdef VERBOSE */
/* printf("mac_dest:%llx %x:%x:%x:%x:%x:%x\n", */
/* macad, */
/* mac_conf_regs->mac.mac_dest_mac1, */
/* mac_conf_regs->mac.mac_dest_mac2, */
/* mac_conf_regs->mac.mac_dest_mac3, */
/* mac_conf_regs->mac.mac_dest_mac4, */
/* mac_conf_regs->mac.mac_dest_mac5, */
/* mac_conf_regs->mac.mac_dest_mac6); */
/* printf("mac_src:%llx %x:%x:%x:%x:%x:%x\n", */
/* detectormacad, */
/* mac_conf_regs->mac.mac_src_mac1, */
/* mac_conf_regs->mac.mac_src_mac2, */
/* mac_conf_regs->mac.mac_src_mac3, */
/* mac_conf_regs->mac.mac_src_mac4, */
/* mac_conf_regs->mac.mac_src_mac5, */
/* mac_conf_regs->mac.mac_src_mac6); */
/* printf("ip_ttl:%x\n",mac_conf_regs->ip.ip_ttl); */
/* printf("det_ip: %x %x\n",detipad, mac_conf_regs->ip.ip_sourceip); */
/* printf("dest_ip: %x %x\n",ipad, mac_conf_regs->ip.ip_destip); */
/* //#endif */
/* //checksum */
/* count=sizeof(mac_conf_regs->ip); */
/* addr=&(mac_conf_regs->ip); */
/* while( count > 1 ) { */
/* sum += *addr++; */
/* count -= 2; */
/* } */
/* if( count > 0 ) sum += *addr; // Add left-over byte, if any */
/* while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits */
/* checksum = (~sum)&0xffff; */
/* mac_conf_regs->ip.ip_chksum = checksum; */
/* //#ifdef VERBOSE */
/* printf("IP header checksum is 0x%x s\n",(unsigned int)(checksum)); */
/* //#endif */
/* mac_conf_regs->udp.udp_srcport = 0xE185; */
/* mac_conf_regs->udp.udp_destport = udpport;//0xC351; */
/* mac_conf_regs->udp.udp_len = udpPacketSize;//0x050E; //was 0x0512; */
/* mac_conf_regs->udp.udp_chksum = 0x0000; */
/* #ifdef VERBOSE */
/* printf("Configuring TSE\n"); */
/* #endif */
/* tse_conf_regs->rev = 0xA00; */
/* tse_conf_regs->scratch = 0xCCCCCCCC; */
/* tse_conf_regs->command_config = 0xB; */
/* tse_conf_regs->mac_0 = 0x17231C00; */
/* tse_conf_regs->mac_1 = 0xCB4A; */
/* tse_conf_regs->frm_length = 0x5DC; //max frame length (1500 bytes) (was 0x41C) */
/* tse_conf_regs->pause_quant = 0x0; */
/* tse_conf_regs->rx_section_empty = 0x7F0; */
/* tse_conf_regs->rx_section_full = 0x10; */
/* tse_conf_regs->tx_section_empty = 0x3F8; //was 0x7F0; */
/* tse_conf_regs->tx_section_full = 0x16; */
/* tse_conf_regs->rx_almost_empty = 0x8; */
/* tse_conf_regs->rx_almost_full = 0x8; */
/* tse_conf_regs->tx_almost_empty = 0x8; */
/* tse_conf_regs->tx_almost_full = 0x3; */
/* tse_conf_regs->mdio_addr0 = 0x12; */
/* tse_conf_regs->mdio_addr1 = 0x0; */
/* mac_conf_regs->cdone = 0xFFFFFFFF; */
/* if(ival) */
/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs.. */
/* else */
/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs.. */
/* val=bus_r(addrr); */
/* #ifdef VERBOSE */
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
/* #endif */
/* // if(val!=0x2840) return -1; */
/* usleep(100000); */
/* if(ival) */
/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs.. */
/* else */
/* bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs.. */
/* val=bus_r(addrr); */
/* #ifdef VERBOSE */
/* printf("Value read from Multi-purpose Reg:%x\n",val); */
/* #endif */
/* // if(val!=0x2820) return -1; */
/* return adcConfigured; */
}
@@ -2103,7 +2031,7 @@ u_int16_t* fifo_read_event(int ns)
int i=0;//, j=0;
/* volatile u_int16_t volatile *dum; */
volatile u_int16_t a;
volatile u_int32_t val;
/*volatile u_int32_t val;*/
// volatile u_int32_t volatile *dum;
// volatile u_int32_t a;
@@ -2329,7 +2257,6 @@ u_int32_t* decode_data(int *datain)
int setDynamicRange(int dr) {
if (dr%16==0 && dr>0) {
dynamicRange=16;
nSamples=dr/16;
@@ -2347,12 +2274,15 @@ int setDynamicRange(int dr) {
int getDynamicRange() {
// dynamicRange=16;
if(myDetectorType == JUNGFRAU){
dynamicRange=16;
return dynamicRange;
}
nSamples=bus_r(NSAMPLES_REG);
getChannels();
dataBytes=nModX*NCHIP*getChannels()*2;
dataBytes=nModX*N_CHIP*getChannels()*2;
return dynamicRange*bus_r(NSAMPLES_REG);//nSamples;
}
int testBus() {
@@ -2400,7 +2330,7 @@ int setStoreInRAM(int b) {
int getChannels() {
int nch=32;
int i;
for (i=0; i<NCHAN; i++) {
for (i=0; i<N_CHAN; i++) {
if (adcDisableMask & (1<<i)) nch--;
}
return nch;
@@ -2428,7 +2358,7 @@ int allocateRAM() {
//#ifdef VERBOSE
printf("reallocating ram %x, size %d\n",(unsigned int)ram_values, size);
printf("reallocating ram %x, size %d\n",(unsigned int)ram_values, (int)size);
//#endif
//+2 was added since dma_memcpy would switch the 16 bit values and the mem is 32 bit
@@ -2466,7 +2396,7 @@ int writeADC(int addr, int val) {
u_int32_t valw,codata,csmask;
int i,cdx,ddx,j;
int i,cdx,ddx;
cdx=0; ddx=1;
csmask=0xfc; // 1111100
@@ -2513,8 +2443,8 @@ int writeADC(int addr, int val) {
int prepareADC(){
printf("Preparing ADC\n");
u_int32_t valw,codata,csmask;
int i,cdx,ddx,j;
u_int32_t codata,csmask;
int cdx,ddx;
cdx=0; ddx=1;
csmask=0x7c; // 1111100
@@ -2574,7 +2504,8 @@ int prepareADC(){
bus_w(ADC_OFFSET_REG,0xbbbbbbbb);
// bus_w(ADC_INVERSION_REG,0x1f6170c6);
return;
return OK;
}
@@ -2861,7 +2792,7 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG));
#endif
memcpy(CounterVals,ptr,dataBytes);
memcpy(CounterVals,ptr,dataBytes); /*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*/
#ifdef VERBOSE
int i;
printf("Copied counter memory block with size of %d bytes..\n",dataBytes);
@@ -2931,7 +2862,7 @@ int resetCounterBlock(int startACQ){
#endif
memcpy(counterVals,ptr,dataBytes);
memcpy(counterVals,ptr,dataBytes);/*warning: passing argument 2 of memcpy discards qualifiers from pointer target type*/
#ifdef VERBOSE
int i;
printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals));
@@ -3003,7 +2934,7 @@ int calibratePedestal(int frames){
int a;
for (a=0;a<1280; a++){
unsigned short v = (frame[a] << 8) + (frame[a] >> 8);
//unsigned short v = (frame[a] << 8) + (frame[a] >> 8);
// printf("%i: %i %i\n",a, frame[a],v);
avg[a] += ((double)frame[a])/(double)frames;
//if(frame[a] == 8191)
@@ -3030,7 +2961,7 @@ int calibratePedestal(int frames){
double nf = (double)numberFrames;
//double nf = (double)numberFrames;
for(i =0; i < 1280; i++){
adc = i / 256;
adcCh = (i - adc * 256) / 32;
@@ -3123,7 +3054,7 @@ uint64_t writePatternWord(int addr, uint64_t word) {
return readPatternWord(addr);
}
uint64_t writePatternIOControl(uint64_t word) {
if (word!=0xffffffffffffffff) {
if (word!=0xffffffffffffffff) { /*warning: integer constant is too large for long type*/
// printf("%llx %llx %lld",get64BitReg(PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB),word);
set64BitReg(word,PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB);
// printf("************ write IOCTRL (%x)\n",PATTERN_IOCTRL_REG_MSB);
@@ -3132,7 +3063,7 @@ uint64_t writePatternIOControl(uint64_t word) {
}
uint64_t writePatternClkControl(uint64_t word) {
if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);
if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);/*warning: integer constant is too large for long type*/
return get64BitReg(PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);
}
@@ -3203,7 +3134,6 @@ int setPatternLoop(int level, int *start, int *stop, int *n) {
int setPatternWaitAddress(int level, int addr) {
int ret=-1;
int reg;
switch (level) {
@@ -3232,7 +3162,6 @@ int setPatternWaitAddress(int level, int addr) {
uint64_t setPatternWaitTime(int level, uint64_t t) {
uint64_t ret=-1;
int reglsb;
int regmsb;
@@ -3266,7 +3195,7 @@ void initDac(int dacnum) {
u_int32_t offw,codata;
u_int16_t valw;
int iru,i,ddx,csdx,cdx;
int i,ddx,csdx,cdx;
@@ -3279,7 +3208,7 @@ void initDac(int dacnum) {
printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx);
codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0));
codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0)); /*warning: suggest parentheses around + or - inside shift*/
valw=0xffff; bus_w(offw,(valw)); // start point
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
@@ -3353,8 +3282,7 @@ int setDac(int dacnum,int dacvalue){
u_int32_t offw,codata;
u_int16_t valw;
int iru,i,ddx,csdx,cdx;
int retval;
int i,ddx,csdx,cdx;
int dacch=0;

View File

@@ -69,6 +69,8 @@ int setContinousReadOut(int d);
int startReceiver(int d);
int setDACRegister(int idac, int val, int imod);
int getDacRegister(int dacnum);
int getTemperature(int tempSensor,int imod);
int initHighVoltage(int val,int imod);
@@ -82,6 +84,8 @@ int getAdcConfigured();
u_int64_t getDetectorNumber();
u_int32_t getFirmwareVersion();
u_int32_t getFirmwareSVNVersion();
int testFifos(void);
u_int32_t testFpga(void);
u_int32_t testRAM(void);
@@ -144,8 +148,16 @@ int setDynamicRange(int dr);
int getDynamicRange();
int getNModBoard();
int setNMod(int n);
int getNMod();
int setStoreInRAM(int b);
int allocateRAM();
int writeADC(int addr, int val);
int prepareADC();
int clearRAM();

View File

@@ -23,10 +23,6 @@
extern int nModX;
//extern int dataBytes;
extern int dynamicRange;
const int nChans=NCHAN;
const int nChips=NCHIP;
const int nDacs=NDAC;
const int nAdcs=NADC;
enum detectorSettings thisSettings;
int sChan, sChip, sMod, sDac, sAdc;
@@ -43,7 +39,19 @@ int *detectorAdcs=NULL;
ROI rois[MAX_ROIS];
int nROI=0;
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 nChans;
extern int nChips;
extern int nDacs;
extern int nAdcs;
int initDetector() {
@@ -55,29 +63,53 @@ int initDetector() {
#ifdef VERBOSE
printf("Board is for %d modules\n",n);
#endif
if(myDetectorType == JUNGFRAU){
N_CHAN=JUNGFRAU_NCHAN;
N_CHIP=JUNGFRAU_NCHIP;
N_DAC=JUNGFRAU_NDAC;
N_ADC=JUNGFRAU_NADC;
N_CHANS=JUNGFRAU_NCHANS;
nChans=N_CHAN;
nChips=N_CHIP;
nDacs=N_DAC;
nAdcs=N_ADC;
}
detectorModules=malloc(n*sizeof(sls_detector_module));
detectorChips=malloc(n*NCHIP*sizeof(int));
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
detectorDacs=malloc(n*NDAC*sizeof(int));
detectorAdcs=malloc(n*NADC*sizeof(int));
detectorDacs=malloc(n*N_DAC*sizeof(int));
detectorAdcs=malloc(n*N_ADC*sizeof(int));
detectorChips=NULL;
detectorChans=NULL;
detectorAdcs=NULL;
if(myDetectorType != JUNGFRAU){
detectorChips=malloc(n*N_CHIP*sizeof(int));
detectorChans=malloc(n*N_CHIP*N_CHAN*sizeof(int));
}
#ifdef VERBOSE
printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n));
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC));
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC));
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*N_DAC));
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*N_ADC));
if(myDetectorType != JUNGFRAU){
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*N_CHIP));
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*N_CHIP*N_CHAN));
}
#endif
for (imod=0; imod<n; imod++) {
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
(detectorModules+imod)->ndac=NDAC;
(detectorModules+imod)->nadc=NADC;
(detectorModules+imod)->nchip=NCHIP;
(detectorModules+imod)->nchan=NCHIP*NCHAN;
(detectorModules+imod)->dacs=detectorDacs+imod*N_DAC;
(detectorModules+imod)->adcs=detectorAdcs+imod*N_ADC;
if(myDetectorType != JUNGFRAU){
(detectorModules+imod)->chipregs=detectorChips+imod*N_CHIP;
(detectorModules+imod)->chanregs=detectorChans+imod*N_CHIP*N_CHAN;
}
(detectorModules+imod)->ndac=N_DAC;
(detectorModules+imod)->nadc=N_ADC;
(detectorModules+imod)->nchip=N_CHIP;
(detectorModules+imod)->nchan=N_CHIP*N_CHAN;
(detectorModules+imod)->module=imod;
(detectorModules+imod)->gain=0;
(detectorModules+imod)->offset=0;
@@ -103,14 +135,12 @@ int initDetector() {
/* dynamicRange=getDynamicRange(); //always 16 not required commented out
nModX=setNMod(-1);*/
//dataBytes=nModX*NCHIP*NCHAN*4;
// dynamicRange=32;
// initChip(0, 0,ALLMOD);
//nModX=n;
//
allocateRAM();
return OK;
}
@@ -211,6 +241,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
// printf("copying gain and offset %f %f to %f %f\n",srcMod->gain,srcMod->offset,destMod->gain,destMod->offset);
if(myDetectorType != JUNGFRAU){
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
if (*((srcMod->chipregs)+ichip)>=0)
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
@@ -219,14 +250,18 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
if (*((srcMod->chanregs)+ichan)>=0)
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
}
}
for (idac=0; idac<(srcMod->ndac); idac++) {
if (*((srcMod->dacs)+idac)>=0)
*((destMod->dacs)+idac)=*((srcMod->dacs)+idac);
}
for (iadc=0; iadc<(srcMod->nadc); iadc++) {
if (*((srcMod->adcs)+iadc)>=0)
*((destMod->adcs)+iadc)=*((srcMod->adcs)+iadc);
}
return ret;
}
@@ -480,15 +515,15 @@ int selChip(const int chip,int imod) {
/* sMod=allSelected; */
/* if (imod>=0 && imod<nModX) { */
/* detectorDacs[idac+NDAC*imod]=v; */
/* detectorDacs[idac+N_DAC*imod]=v; */
/* #ifdef VERBOSE */
/* printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, (unsigned int)(detectorDacs+idac+NDAC*imod)); */
/* printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, (unsigned int)(detectorDacs+idac+N_DAC*imod)); */
/* #endif */
/* setDACRegister(idac,v,imod); */
/* } else if (imod==ALLMOD) { */
/* for (im=0; im<nModX; im++) { */
/* detectorDacs[idac+NDAC*im]=v; */
/* detectorDacs[idac+N_DAC*im]=v; */
/* setDACRegister(idac,v,im); */
/* } */
/* } */
@@ -544,9 +579,9 @@ int selChip(const int chip,int imod) {
/* int initDACbyIndex(int ind,int val, int imod) { */
/* int v; */
/* const int partref[NDAC]=PARTREF; */
/* const int partr1[NDAC]=PARTR1; */
/* const int partr2[NDAC]=PARTR2; */
/* const int partref[N_DAC]=PARTREF; */
/* const int partr1[N_DAC]=PARTR1; */
/* const int partr2[N_DAC]=PARTR2; */
/* int ref=partref[ind]; */
/* int r1=partr1[ind]; */
@@ -561,8 +596,8 @@ int selChip(const int chip,int imod) {
/* int initDACbyIndexDACU(int ind, int val, int imod) { */
/* // const double daccs[NDAC]=DACCS; */
/* // const double dacaddr[NDAC]=DACADDR; */
/* // const double daccs[N_DAC]=DACCS; */
/* // const double dacaddr[N_DAC]=DACADDR; */
/* // int cs=daccs[ind]; */
/* // int addr=dacaddr[ind]; */
@@ -573,7 +608,7 @@ int selChip(const int chip,int imod) {
/* initDAC(ind,val, imod); */
/* if (imod>=0 && imod<nModX) { */
/* // return detectorDacs[ind+imod*NDAC]; */
/* // return detectorDacs[ind+imod*N_DAC]; */
/* return setDACRegister(ind, -1, imod); */
/* } */
/* else { */
@@ -585,7 +620,7 @@ int selChip(const int chip,int imod) {
/* #ifdef VERBOSE */
/* printf("mod %d dac %d val %d\n",im,ind,setDACRegister(ind, -1, im)); */
/* #endif */
/* //if (detectorDacs[ind+im*NDAC]!=detectorDacs[ind]) { */
/* //if (detectorDacs[ind+im*N_DAC]!=detectorDacs[ind]) { */
/* if (setDACRegister(ind, -1, im)!=setDACRegister(ind, -1, 0)) { */
/* #ifdef VERBOSE */
@@ -636,7 +671,7 @@ int selChip(const int chip,int imod) {
/* } */
/* if (myg>0 && myo>0) { */
/* //ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg; */
/* //ethr=(myo-detectorDacs[VTHRESH+imod*N_DAC])*1000/myg; */
/* ethr=(myo-setDACRegister(VDAC0,-1,imod))*1000/myg;//edited by dhanya */
/* // else */
@@ -644,7 +679,7 @@ int selChip(const int chip,int imod) {
/* } */
/* #ifdef VERBOSE */
/* //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]); */
/* //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*N_DAC]); */
/* printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VDAC0,-1,imod)));//edited by dhanya */
/* printf("Threshold energy of module %d is %d eV\n", imod, ethr); */
/* #endif */
@@ -722,7 +757,7 @@ int selChip(const int chip,int imod) {
/* if (detectorDacs) { */
/* if (imod<getNModBoard()) */
/* if (ind<(detectorModules+imod)->ndac) */
/* return (detectorDacs[ind+imod*NDAC]); */
/* return (detectorDacs[ind+imod*N_DAC]); */
/* } */
/* return FAIL; */
/* *\/ */
@@ -847,37 +882,50 @@ int setSettings(int i, int imod) {
else
printf("\ninside set settings wit settings=%d...\n",i);
#endif
int confgain[] = CONF_GAIN;
int isett=-2,retval;
int isett=-1,val=-1,retval=-1;
enum conf_gain {
dynamic = 0x0f00, //dynamic
dynamichighgain0 = 0x0f01, //dynamichighgain0
fixgain1 = 0x0f02, //fixgain1
fixgain2 = 0x0f06, //fixgain2
forceswitchgain1 = 0x1f00, //forceswitchgain1
forceswitchgain2 = 0x3f00 //forceswitchgain2
};
//reading settings
if(i==GET_SETTINGS){
retval=initConfGainByModule(i,i,imod);
if(retval==i)
//determine conf value to write
if(i!=GET_SETTINGS){
switch(i){
case DYNAMICGAIN: val = dynamic;break;
case DYNAMICHG0: val = dynamichighgain0;break;
case FIXGAIN1: val = fixgain1;break;
case FIXGAIN2: val = fixgain2;break;
case FORCESWITCHG1: val = forceswitchgain1;break;
case FORCESWITCHG2: val = forceswitchgain2;break;
default:
printf("Error: This settings is not defined for this detector %d\n",i);
return GET_SETTINGS;
}
}
retval=initConfGainByModule(i,val,imod);
switch(retval){
case dynamic: isett=DYNAMICGAIN; break;
case dynamichighgain0: isett=DYNAMICHG0; break;
case fixgain1: isett=FIXGAIN1; break;
case fixgain2: isett=FIXGAIN2; break;
case forceswitchgain1: isett=FORCESWITCHG1; break;
case forceswitchgain2: isett=FORCESWITCHG2; break;
default:
isett=UNDEFINED;
printf("Error:Wrong settings read out from Gain Reg 0x%x\n",retval);
break;
}
//writing settings
else{
retval=initConfGainByModule(i,confgain[i],imod);
if(retval!=i)
isett=UNDEFINED;
}
//if error while read/writing
if(isett==UNDEFINED)
printf("Error:Weird Value read back from the Gain/Settings Reg\n");
else{
//validating the settings read back
if((retval>=HIGHGAIN)&&(retval<=VERYHIGHGAIN))
isett=retval;
else{
isett=UNDEFINED;
printf("Error:Wrong Settings Read out:%d\n",retval);
}
}
thisSettings=isett;
#ifdef VERBOSE
//#ifdef VERBOSE
printf("detector settings are %d\n",thisSettings);
#endif
//#endif
return thisSettings;
}
@@ -886,7 +934,7 @@ int setSettings(int i, int imod) {
/* Initialization*/
int initChannelbyNumber(sls_detector_channel myChan) {
int initChannelbyNumber(sls_detector_channel myChan) {printf("in init channel by number\n");
int reg=myChan.reg;
int ft=reg & TRIM_DR;
int cae=(reg>>(NTRIMBITS))&1;
@@ -930,7 +978,7 @@ int getChannelbyNumber(sls_detector_channel* myChan) {
if (detectorChans) {
if (imod<nModX && imod>=0) {
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
myChan->reg=detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan];
myChan->reg=detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan];
return OK;
}
}
@@ -942,7 +990,7 @@ int getTrimbit(int imod, int ichip, int ichan) {
if (detectorChans) {
if (imod<getNModBoard() && imod>=0)
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
return (detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan] & TRIM_DR);
return (detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan] & TRIM_DR);
}
return -1;
@@ -966,8 +1014,8 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
if (sChan==allSelected) {
// printf("initializing all channels ft=%d coe=%d\n",ft,coe);
chanmi=0;
chanma=NCHAN;
} else if (sChan==noneSelected || sChan>NCHAN || sChan<0) {
chanma=N_CHAN;
} else if (sChan==noneSelected || sChan>N_CHAN || sChan<0) {
// printf("initializing no channels ft=%d coe=%d\n",ft,coe);
chanmi=0;
chanma=-1;
@@ -980,8 +1028,8 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
if (sChip==allSelected) {
// printf("initializing all chips\n");
chipmi=0;
chipma=NCHIP;
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
chipma=N_CHIP;
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
// printf("initializing no chips\n");
chipmi=0;
chipma=-1;
@@ -1009,12 +1057,12 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
for (ichip=chipmi; ichip<chipma; ichip++) {
for (ichan=chanmi; ichan<chanma; ichan++) {
#ifdef VERBOSE
// printf("im=%d ichi=%d icha=%d tot=%d reg=%x\n",im,ichip, ichan, im*NCHAN*NCHIP+ichip*NCHAN+ichan,detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
// printf("im=%d ichi=%d icha=%d tot=%d reg=%x\n",im,ichip, ichan, im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan,detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
#endif
detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]= ft | (cae<<(NTRIMBITS+1)) | (ae<<(NTRIMBITS+2)) | (coe<<(NTRIMBITS+3)) | (ocoe<<(NTRIMBITS+4)) | (counts<<(NTRIMBITS+5));
detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]= ft | (cae<<(NTRIMBITS+1)) | (ae<<(NTRIMBITS+2)) | (coe<<(NTRIMBITS+3)) | (ocoe<<(NTRIMBITS+4)) | (counts<<(NTRIMBITS+5));
#ifdef VERBOSE
//printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+ichan, detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
// printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+ichan, detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
//printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan, detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
// printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan, detectorChans[im*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]);
#endif
}
}
@@ -1214,9 +1262,9 @@ int getChipbyNumber(sls_detector_chip* myChip){
if (detectorChips) {
if (imod<nModX)
if (ichip<(detectorModules+imod)->nchip) {
myChip->reg=detectorChips[ichip+imod*NCHIP];
myChip->nchan=NCHAN;
myChip->chanregs=detectorChans+imod*NCHAN*NCHIP+ichip*NCHIP;
myChip->reg=detectorChips[ichip+imod*N_CHIP];
myChip->nchan=N_CHAN;
myChip->chanregs=detectorChans+imod*N_CHAN*N_CHIP+ichip*N_CHIP;
return OK;
}
}
@@ -1322,8 +1370,8 @@ int initChip(int obe, int ow,int imod){
if (sChip==allSelected) {
chipmi=0;
chipma=NCHIP;
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
chipma=N_CHIP;
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
chipmi=0;
chipma=-1;
} else {
@@ -1347,9 +1395,9 @@ int initChip(int obe, int ow,int imod){
for (im=modmi; im<modma; im++) {
for (ichip=chipmi; ichip<chipma; ichip++) {
// printf("imod %d ichip %d\n",im,ichip);
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
detectorChips[im*N_CHIP+ichip]=obe | (ow<<1);
#ifdef VERBOSE
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*N_CHIP+ichip],detectorChips+im*N_CHIP+ichip);
#endif
}
}
@@ -1422,8 +1470,8 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
if (sChip==allSelected) {
chipmi=0;
chipma=NCHIP;
} else if (sChip==noneSelected || sChip>NCHIP || sChip<0) {
chipma=N_CHIP;
} else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) {
chipmi=0;
chipma=-1;
} else {
@@ -1447,9 +1495,9 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
for (im=modmi; im<modma; im++) {
for (ichip=chipmi; ichip<chipma; ichip++) {
// printf("imod %d ichip %d\n",im,ichip);
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
detectorChips[im*N_CHIP+ichip]=obe | (ow<<1);
#ifdef VERBOSE
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*N_CHIP+ichip],detectorChips+im*N_CHIP+ichip);
#endif
}
}
@@ -1522,15 +1570,16 @@ int initMCBregisters(int cm, int imod){
int initModulebyNumber(sls_detector_module myMod) {
printf("\ninside initmoduleynumber..\n");
printf("\ninside initmoduleynumberrrr..\n");
printf("000\n");
int nchip,nchan;//int ichip, nchip, ichan, nchan;
int im, modmi,modma;
// int ft, cae, ae, coe, ocoe, counts, chanreg;
int imod;
// int obe;
// int ow;
int v[NDAC];
/* int v[N_DAC];*/
int retval =-1, idac;
nchip=myMod.nchip;
@@ -1553,12 +1602,10 @@ int initModulebyNumber(sls_detector_module myMod) {
modma=sMod+1;
}
printf("222\n");
/*
for (idac=0; idac<NDAC; idac++)
for (idac=0; idac<N_DAC; idac++)
v[idac]=(myMod.dacs)[idac];
*/
v[VDAC0]=(myMod.dacs)[0];
v[VDAC1]=(myMod.dacs)[1];
@@ -1580,10 +1627,17 @@ int initModulebyNumber(sls_detector_module myMod) {
printf("vdac6=%d\n",v[VDAC6]);
printf("vdac7=%d\n",v[VDAC7]);
#endif
*/
printf("ndac:%d\n",N_DAC);
// initDACs(v,imod);
// initMCBregisters(myMod.reg,imod);
for (idac=0; idac<N_DAC; idac++){
retval = setDac(idac,(myMod.dacs)[idac]);
if(retval ==(myMod.dacs)[idac])
printf("Setting dac %d to %d\n",idac,retval);
else
printf("Error: Could not set dac %d, wrote %d but read %d\n",idac,(myMod.dacs)[idac],retval);
}
if (detectorModules) {
for (im=modmi; im<modma; im++) {
@@ -1593,11 +1647,9 @@ int initModulebyNumber(sls_detector_module myMod) {
copyModule(detectorModules+im,&myMod);
}
}
//setting the conf gain and the settings register
setSettings(myMod.reg,imod);
return myMod.reg;
return thisSettings;
}
@@ -1739,11 +1791,11 @@ int readOutChan(int *val) {
for (k=0; k<nModX; k++) {
v=readin(k);
//v=bus_r(MCB_DOUT_REG_OFF+(k<<SHIFTMOD)) & 0x3ff;
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
if (i==0)
*(val+j+k*NCHIP)=0;
*(val+j+k*N_CHIP)=0;
if (v & (1<<j)) {
*(val+j+k*NCHIP)= *(val+j+k*NCHIP) | (1 << i);
*(val+j+k*N_CHIP)= *(val+j+k*N_CHIP) | (1 << i);
}
}
}
@@ -1877,7 +1929,7 @@ int testShiftStSel(int imod) {
int val,i,j,k;
printf("testing shift stsel for module %d\n", imod);
setCSregister(ALLMOD);
for (i=0; i<NCHAN; i++) {
for (i=0; i<N_CHAN; i++) {
if (i%2) {
putout("0100011000000000",ALLMOD);
putout("0110011000000000",ALLMOD);
@@ -1889,7 +1941,7 @@ int testShiftStSel(int imod) {
}
}
putout("0010011000000000",ALLMOD);
for (i=0; i<NCHAN; i++) {
for (i=0; i<N_CHAN; i++) {
putout("0000011000000000",ALLMOD);
@@ -1897,7 +1949,7 @@ int testShiftStSel(int imod) {
//for (k=0; k<nModX; k++) {
val=readin(k);
//val=bus_r(MCB_DOUT_REG_OFF+(k<<SHIFTMOD)) & 0x3ff;
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
if ( (val & 1<<j)>0 && i%2==0) {
printf("Shift stsel: module %d chip %i bit %d read %d instead of %d \n",k,j,i,val & 1<< j, i%2);
result++;
@@ -1926,7 +1978,7 @@ int testShiftStSel(int imod) {
int testDataInOut(int num, int imod) {
int val[NCHIP*nModX], result=OK;
int val[N_CHIP*nModX], result=OK;
int ich, ichip;
setCSregister(ALLMOD);
printf("Testing data in out for module %d pattern 0x%x\n", imod, num);
@@ -1936,14 +1988,14 @@ int testDataInOut(int num, int imod) {
setCSregister(ALLMOD);
initChip(0, 0,ALLMOD);
clearSSregister(ALLMOD);
for (ich=0; ich<NCHAN; ich++) {
for (ich=0; ich<N_CHAN; ich++) {
nextStrip(ALLMOD);
readOutChan(val);
//imod=0;
//for (imod=0; imod<nModX; imod++) {
for (ichip=0; ichip<NCHIP; ichip++) {
if (val[ichip+imod*NCHIP]!=num) {
printf("Test datain out: Channel %d read %x instead of %x\n", (imod*NCHIP+ichip)*NCHAN+ich, val[ichip+NCHIP*imod], num);
for (ichip=0; ichip<N_CHIP; ichip++) {
if (val[ichip+imod*N_CHIP]!=num) {
printf("Test datain out: Channel %d read %x instead of %x\n", (imod*N_CHIP+ichip)*N_CHAN+ich, val[ichip+N_CHIP*imod], num);
result++;
}
}
@@ -1970,7 +2022,7 @@ int testExtPulse(int imod) {
putout("0000000000000000",ALLMOD);
putout("0000100000000000",ALLMOD);
putout("0000000000000000",ALLMOD);
for (i=0; i<NCHAN; i++) {
for (i=0; i<N_CHAN; i++) {
putout("0000000000000000",ALLMOD);
putout("0000000000001000",ALLMOD);
putout("0000000000000000",ALLMOD);
@@ -1989,11 +2041,11 @@ int testExtPulse(int imod) {
// val1=fifo_read_event();
//imod=0;
//for (imod=0; imod<nModX; imod++) {
for (ichip=0; ichip<NCHIP; ichip++) {
for (ichan=0; ichan<NCHAN; ichan++) {//
if ((*(val1+ichan+(ichip+imod*NCHIP)*NCHAN))!=ichan) {
for (ichip=0; ichip<N_CHIP; ichip++) {
for (ichan=0; ichan<N_CHAN; ichan++) {//
if ((*(val1+ichan+(ichip+imod*N_CHIP)*N_CHAN))!=ichan) {
result++;
printf("Counter test: channel %d read %d instead of %d\n",ichan+(ichip+imod*NCHIP)*NCHAN, val1[ichan+(ichip+imod*NCHIP)*NCHAN], ichan);
printf("Counter test: channel %d read %d instead of %d\n",ichan+(ichip+imod*N_CHIP)*N_CHAN, val1[ichan+(ichip+imod*N_CHIP)*N_CHAN], ichan);
}
}
}
@@ -2035,9 +2087,9 @@ int testExtPulseMux(int imod, int ow) {
counterClear(ALLMOD);
initChipWithProbes(0, ow,0,ALLMOD);
// initChip(0, ow,ALLMOD);
for (ichip=0; ichip<NCHIP; ichip++) {
for (ichip=0; ichip<N_CHIP; ichip++) {
setSSregister(ALLMOD);
for (i=0; i<NCHAN; i++) {
for (i=0; i<N_CHAN; i++) {
putout("0000000000000000",ALLMOD);
putout("0000000000001000",ALLMOD);
putout("0000000000000000",ALLMOD);
@@ -2061,16 +2113,16 @@ int testExtPulseMux(int imod, int ow) {
printf("no data found in fifos\n");
return 1;
}
for (ichip=0; ichip<NCHIP; ichip++) {
for (ichip=0; ichip<N_CHIP; ichip++) {
chipr=0;
for (ichan=0; ichan<NCHAN; ichan++) {
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
for (ichan=0; ichan<N_CHAN; ichan++) {
ind=ichan+(ichip+imod*N_CHIP)*N_CHAN;
v=values[ind];
vright=(ichan*(ichip+1))&nbit_mask;
if (v!=vright) {
result++;
chipr++;
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*N_CHIP)*N_CHAN, ichip, v, vright);
//break;
}
//printf("\n");
@@ -2136,15 +2188,15 @@ int testDataInOutMux(int imod, int ow, int num) {
printf("no data found in fifos\n");
return 1;
}
for (ichip=0; ichip<NCHIP; ichip++) {
for (ichip=0; ichip<N_CHIP; ichip++) {
chipr=0;
for (ichan=0; ichan<NCHAN; ichan++) {
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
for (ichan=0; ichan<N_CHAN; ichan++) {
ind=ichan+(ichip+imod*N_CHIP)*N_CHAN;
v=values[ind];
if (v!=vright) {
result++;
chipr++;
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*N_CHIP)*N_CHAN, ichip, v, vright);
//break;
}
//printf("\n");
@@ -2231,7 +2283,7 @@ int testOutMux(int imod) {
#ifdef DEBUGOUT
printf("%d %x\n",i*dist,val);
#endif
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
v=val & 1<< j;
if (pat & (1<<(i*dist))) {
if (v==0) {
@@ -2259,7 +2311,7 @@ int testOutMux(int imod) {
#ifdef DEBUGOUT
printf("%d %x\n",i*dist, val);
#endif
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
v=val & 1<< j;
if (pat & (1<<(i*dist))) {
if (v==0) {
@@ -2292,7 +2344,7 @@ int testOutMux(int imod) {
#ifdef DEBUGOUT
printf("%d %x\n",i*dist, val);
#endif
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
v=val & 1<< j;
if (pat & (1<<(i*dist))) {
if (v==0) {
@@ -2320,7 +2372,7 @@ int testOutMux(int imod) {
#ifdef DEBUGOUT
printf("%d %x\n",i*dist, val);
#endif
for (j=0; j<NCHIP; j++) {
for (j=0; j<N_CHIP; j++) {
v=val & 1<< j;
if (pat & (1<<(i*dist))) {
if (v==0) {
@@ -2488,9 +2540,9 @@ int calibration_sensor(int num, int *v, int *dacs) {
selChip(ichip,imod);
for (ich=0; ich<128; ich++){
selChannel(ich,imod);
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
clearCounter(imod);
//initChannel(*(dacs+ichip*NCHAN+ich),FALSE,FALSE,TRUE,FALSE,0); //disable channel;
//initChannel(*(dacs+ichip*N_CHAN+ich),FALSE,FALSE,TRUE,FALSE,0); //disable channel;
}
}
}
@@ -2498,11 +2550,11 @@ int calibration_sensor(int num, int *v, int *dacs) {
for (imod=0; imod<nModX; imod++) {
//selMod(imod);
initMCBregisters(1,imod);
for (ich=0; ich<NCHAN; ich++){
for (ichip=0; ichip<NCHIP; ichip++) {
for (ich=0; ich<N_CHAN; ich++){
for (ichip=0; ichip<N_CHIP; ichip++) {
selChip(ichip,imod); // select channel
selChannel(ich,imod); // select channel
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),0,0,1,0,0,imod); // enable channel
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),0,0,1,0,0,imod); // enable channel
clearCounter(imod);
}
setCSregister(imod);
@@ -2516,11 +2568,11 @@ int calibration_sensor(int num, int *v, int *dacs) {
}
readOutChan(val); // readout channel
for (imod=0; imod<nModX; imod++) {
for (ichip=0; ichip<NCHIP; ichip++) {
*(v+(ichip+imod*NCHIP)*NCHAN+ich)=val[ichip+imod*NCHIP];
for (ichip=0; ichip<N_CHIP; ichip++) {
*(v+(ichip+imod*N_CHIP)*N_CHAN+ich)=val[ichip+imod*N_CHIP];
selChip(ichip,imod); // select channel
selChannel(ich,imod); // select channel
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
}
}
}
@@ -2542,17 +2594,17 @@ int calibration_chip(int num, int *v, int *dacs) {
for (ich=0; ich<128; ich++){
selChannel(ich,imod);
clearCounter(imod);
initChannel(*(dacs+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
initChannel(*(dacs+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
}
}
}
for (ich=0; ich<NCHAN; ich++){
for (ich=0; ich<N_CHAN; ich++){
for (imod=0; imod<nModX; imod++) {
//selMod(imod);
for (ichip=0; ichip<NCHIP; ichip++) {
for (ichip=0; ichip<N_CHIP; ichip++) {
selChip(ichip,imod); // select channel
selChannel(ich,imod); // select channel
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),1,0,1,0,0,imod); // enable channel
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),1,0,1,0,0,imod); // enable channel
clearCounter(imod);
}
}
@@ -2568,10 +2620,10 @@ int calibration_chip(int num, int *v, int *dacs) {
for (imod=0; imod<nModX; imod++) {
//selMod(imod);
for (ichip=0; ichip<10; ichip++) {
*(v+(ichip+imod*NCHIP)*NCHAN+ich)=val[ichip+imod*NCHIP];
*(v+(ichip+imod*N_CHIP)*N_CHAN+ich)=val[ichip+imod*N_CHIP];
selChip(ichip,imod); // select chip
selChannel(ich,imod); // select channel
initChannel(*(dacs+imod*NCHAN*NCHIP+ichip*NCHAN+ich),0,0,0,0,0,imod); //disable channel;
initChannel(*(dacs+imod*N_CHAN*N_CHIP+ichip*N_CHAN+ich),0,0,0,0,0,imod); //disable channel;
}
}
}

View File

@@ -9,9 +9,6 @@
#define RGSH1VALS {300,200,400}
#define RGSH2VALS {260,300,260}
//high,dynamic,low,medium,very high
#define CONF_GAIN {0,0, 0, 1, 6, 2, 1}//dynamic gain confgain yet to be figured out-probably 8 or 16
#define DEFAULTGAIN {11.66,9.32,14.99}
#define DEFAULTOFFSET {817.5,828.6,804.2}
@@ -107,13 +104,16 @@ int selMod(int mod,int imod );
/* int set_one_dac(int imod); */
/* int initDAC(int dac_addr, int value,int imod ); */
/* int initDACs(int* v,int imod ); */
/* int setSettings(int i,int imod); */
/* int initDACbyIndex(int ind,int val, int imod); */
/* int initDACbyIndexDACU(int ind,int val, int imod); */
/* int getDACbyIndexDACU(int ind, int imod); */
/* int getThresholdEnergy(); */
/* int setThresholdEnergy(int ethr); */
int setSettings(int i,int imod);
/* Other DAC index routines*/
int getTemperatureByModule(int tempSensor, int imod);
int initHighVoltageByModule(int val, int imod);

View File

@@ -19,96 +19,21 @@
#define FPGA_INIT_PAT 0x60008
#define FPGA_INIT_ADDR 0xb0000000
//#ifdef JUNGFRAU_DHANYA
#define POWER_ON_REG 0x5e<<11
#define ADCREG1 8 //same as PLL_BANDWIDTH_REG
#define ADCREG2 20 //0x14
#define ADCREG3 4 //same as PLL_M_COUNTER_REG
#define ADCREG4 5 //same as PLL_C_COUNTER_REG
#define ADCREG_VREFS 24 //0x18
#define DBIT_PIPELINE_REG 89<<11 //0x59 same PATTERN_N_LOOP2_REG
#define MEM_MACHINE_FIFOS_REG 79<<11 //0x4f same as CONTROL_REG
#define CONFGAIN_REG 93<<11 //0x5d same as DAQ_REG
#define ADC_PIPELINE_REG 66<<11 //0x42 same as ADC_OFFSET_REG
//#endif
/* constant FPGAVersionReg_c : integer:= 0; */
/* constant FixedPatternReg_c : integer:= 1; */
/* constant StatusReg_c : integer:= 2; */
/* constant LookAtMeReg_c : integer:= 3; */
/* constant SystemStatusReg_c : integer:= 4; */
/* constant PLL_ParamOutReg_c : integer:=5; -- RO register to check control signals going to the chip */
/* --time registers use only even numbers! */
/* constant TimeFromStartReg_c : integer:= 16; */
/* --constant TimeFromStartReg_c : integer:= 17; MSB */
/* constant GetDelayReg_c : integer:= 18; */
/* --constant GetDelayReg_c : integer:= 19; MSB */
/* constant GetCyclesReg_c : integer:= 20; */
/* --constant GetTrainsReg_c : integer:= 21; MSB */
/* constant GetFramesReg_c : integer:= 22; */
/* --constant GetFramesReg_c : integer:= 23; MSB */
/* constant GetPeriodReg_c : integer:= 24; */
/* --constant GetPeriodReg_c : integer:= 25; MSB */
/* constant GetExpTimeReg_c : integer:= 26; */
/* --constant GetExpTimeReg_c : integer:= 27; MSB */
/* constant GetGatesReg_c : integer:= 28; */
/* --constant GetGatesReg_c : integer:= 29; MSB */
/* -----rw: */
/* constant DACReg_c : integer:= 64; */
/* constant ADCWriteReg_c : integer:= 65; */
/* constant ADCsyncReg_c : integer:= 66; */
/* constant HVReg_c : integer:= 67; */
/* constant DummyReg_c : integer:= 68; */
/* constant rx_udpip_AReg_c : integer:= 69; */
/* constant udpports_AReg_c : integer:= 70; */
/* constant rx_udpmacL_AReg_c : integer:= 71; */
/* constant rx_udpmacH_AReg_c : integer:= 72; */
/* constant detectormacL_AReg_c : integer:= 73; */
/* constant detectormacH_AReg_c : integer:= 74; */
/* constant detectorip_AReg_c : integer:= 75; */
/* constant ipchksum_AReg_c : integer:= 76; */
/* constant ConfigReg_c : integer:= 77; */
/* constant ExtSignalReg_c : integer:= 78; */
/* constant ControlReg_c : integer:= 79; */
/* constant PLL_ParamReg_c : integer:= 80; */
/* constant PLL_CntrlReg_c : integer:=81; */
/* --time registers use only even numbers! */
/* -- DELAY_AFTER_TRIGGER, */
/* constant SetDelayReg_c : integer:= 96; */
/* --constant SetDelayReg_c : integer:= 97; MSB */
/* -- CYCLES_NUMBER, */
/* constant SetCyclesReg_c : integer:= 98; */
/* --constant SetCyclesReg_c : integer:= 99;MSB */
/* -- FRAME_NUMBER, */
/* constant SetFramesReg_c : integer:= 100; */
/* --constant SetFramesReg_c : integer:= 101; MSB */
/* -- FRAME_PERIOD, */
/* constant SetPeriodReg_c : integer:= 102; */
/* --constant SetPeriodReg_c : integer:= 103; MSB */
/* -- ACQUISITION_TIME, */
/* constant SetExpTimeReg_c : integer:= 104; */
/* --constant SetExpTimeReg_c : integer:= 105; MSB */
/* -- GATES_NUMBER, */
/* constant SetGatesReg_c : integer:= 106; */
/* --constant SetGatesReg_c : integer:= 107; MSB */
#define ADC_OFFSET_REG 66<<11 //same as ADC_PIPELINE_REG
#define ADC_INVERSION_REG 67<<11
#define DAC_REG 64<<11//0x17<<11// control the dacs
//ADC
@@ -116,8 +41,8 @@
//#define ADC_SYNC_REG 66<<11//0x19<<11
//#define HV_REG 67<<11//0x20<<11
#define ADC_OFFSET_REG 66<<11
#define ADC_INVERSION_REG 67<<11
//#define MUTIME_REG 0x1a<<11
//temperature
@@ -223,17 +148,22 @@
#define PLL_CNTRL_REG 81<<11//0x34<<11
#ifdef NEW_GBE_INTERFACE
#define GBE_PARAM_OUT_REG 40<<11
#define GBE_PARAM_REG 69<<11
#define GBE_CNTRL_REG 70<<11
#else
#define RX_UDP_AREG 69<<11 //rx_udpip_AReg_c : integer:= 69; *\/
#define UDPPORTS_AREG 70<<11// udpports_AReg_c : integer:= 70; *\/
#define RX_UDPMACL_AREG 71<<11//rx_udpmacL_AReg_c : integer:= 71; *\/
#define RX_UDPMACH_AREG 72<<11//rx_udpmacH_AReg_c : integer:= 72; *\/
#define DETECTORMACL_AREG 73<<11//detectormacL_AReg_c : integer:= 73; *\/
#define DETECTORMACH_AREG 74<<11//detectormacH_AReg_c : integer:= 74; *\/
#define DETECTORIP_AREG 75<<11//detectorip_AReg_c : integer:= 75; *\/
#define IPCHKSUM_AREG 76<<11//ipchksum_AReg_c : integer:= 76; *\/ */
#endif
#define RX_UDP_AREG 69<<11 //rx_udpip_AReg_c : integer:= 69; */
#define UDPPORTS_AREG 70<<11// udpports_AReg_c : integer:= 70; */
#define RX_UDPMACL_AREG 71<<11//rx_udpmacL_AReg_c : integer:= 71; */
#define RX_UDPMACH_AREG 72<<11//rx_udpmacH_AReg_c : integer:= 72; */
#define DETECTORMACL_AREG 73<<11//detectormacL_AReg_c : integer:= 73; */
#define DETECTORMACH_AREG 74<<11//detectormacH_AReg_c : integer:= 74; */
#define DETECTORIP_AREG 75<<11//detectorip_AReg_c : integer:= 75; */
#define IPCHKSUM_AREG 76<<11//ipchksum_AReg_c : integer:= 76; */
#define PATTERN_CNTRL_REG 82<<11
#define PATTERN_LIMITS_AREG 83<<11
@@ -255,6 +185,7 @@
#define DAQ_REG 93<<11
#define ADC_LATCH_DISABLE_REG 94<<11
#define HV_REG 95<<11
#define PATTERN_IOCTRL_REG_LSB 108<<11
#define PATTERN_IOCTRL_REG_MSB 109<<11
@@ -367,14 +298,16 @@
#define READSTATE_0_BIT 0x00000100
#define READSTATE_1_BIT 0x00000200
#define READSTATE_2_BIT 0x00000400
#define PLL_RECONFIG_BUSY 0x00100000
#define SOME_FIFO_FULL_BIT 0x00000800 // error!
#define RUNSTATE_0_BIT 0x00001000
#define RUNSTATE_1_BIT 0x00002000
#define RUNSTATE_2_BIT 0x00004000
#define SOME_FIFO_FULL_BIT 0x00008000 // error!
#define STOPPED_BIT 0x00008000 // error!
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
#define RUNMACHINE_BUSY_BIT 0x00020000
#define READMACHINE_BUSY_BIT 0x00040000
#define PLL_RECONFIG_BUSY 0x00100000
@@ -536,8 +469,40 @@
#define PPL_BW_PARAM_DEFAULT 0x2EE0
#define PPL_VCO_PARAM_DEFAULT 0x1
#define PLL_VCO_FREQ_MHZ 480//800
#define NEW_PLL_RECONFIG
#ifdef NEW_PLL_RECONFIG
#define PLL_VCO_FREQ_MHZ 400//480//800
#else
#define PLL_VCO_FREQ_MHZ 480//800
#endif
/*
GBE parameter and control registers definitions
*/
#define GBE_CTRL_WSTROBE 0
#define GBE_CTRL_VAR_OFFSET 16
#define GBE_CTRL_VAR_MASK 0XF
#define GBE_CTRL_RAMADDR_OFFSET 24
#define GBE_CTRL_RAMADDR_MASK 0X3F
#define GBE_CTRL_INTERFACE 23
#define RX_UDP_IP_ADDR 0
#define RX_UDP_PORTS_ADDR 1
#define RX_UDP_MAC_L_ADDR 2
#define RX_UDP_MAC_H_ADDR 3
#define IPCHECKSUM_ADDR 4
#define GBE_DELAY_ADDR 5
#define GBE_RESERVED1_ADDR 6
#define GBE_RESERVED2_ADDR 7
#define DETECTOR_MAC_L_ADDR 8
#define DETECTOR_MAC_H_ADDR 9
#define DETECTOR_IP_ADDR 10

View File

@@ -3,9 +3,11 @@
#include "sls_detector_defs.h"
#include <stdlib.h>
#include "communication_funcs.h"
#include "server_funcs.h"
#include <stdlib.h>
#include <string.h>
extern int sockfd;

View File

@@ -7,25 +7,30 @@
// Hardware definitions
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NCHAN 32
#define NCHIP 1
#define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD (NMAXMODX*NMAXMODY)
#define NDAC 16
#define NADC 1
#define NDAC 16
#define NMAXMODX 1
#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 NCHANS (NCHAN*NCHIP*NMAXMOD)
#define NDACS (NDAC*NMAXMOD)
#define NTRIMBITS 6
#define NCOUNTBITS 24

View File

@@ -4,7 +4,6 @@
#include "server_defs.h"
#include "firmware_funcs.h"
#include "mcb_funcs.h"
#include "trimming_funcs.h"
#include "registers_m.h"
#include "gitInfoMoench.h"
@@ -56,19 +55,26 @@ extern int withGotthard;
int adcvpp=0x4;
/** for jungfrau reinitializing macro later */
int N_CHAN=NCHAN;
int N_CHIP=NCHIP;
int N_DAC=NDAC;
int N_ADC=NADC;
int N_CHANS=NCHANS;
int init_detector(int b, int checkType) {
int i;
int retvalsize,ret;
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
exit(1);
}
//
//print version
printf("v: 0x%x\n",bus_r(FPGA_VERSION_REG));
printf("fp: 0x%x\n",bus_r(FIX_PATT_REG));
//checktype
if (checkType) {
printf("Bus test... (checktype is %d; b is %d)",checkType,b );
for (i=0; i<1000000; i++) {
@@ -80,7 +86,9 @@ int init_detector(int b, int checkType) {
printf("Finished\n");
}else
printf("(checktype is %d; b is %d)",checkType,b );
//confirm if it is really moench
//confirm the detector type
switch ((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) {
case MOENCH03_MODULE_ID:
myDetectorType=MOENCH;
@@ -100,20 +108,15 @@ int init_detector(int b, int checkType) {
default:
myDetectorType=GENERIC;
printf("Unknown detector type %02x\n",(bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET);
break;
}
printf("Detector type is %d\n", myDetectorType);
// return OK;
//control server only--
if (b) {
resetPLL();
bus_w16(CONTROL_REG, SYNC_RESET);
bus_w16(CONTROL_REG, 0);
bus_w16(CONTROL_REG, GB10_RESET_BIT);
@@ -121,26 +124,94 @@ int init_detector(int b, int checkType) {
#ifdef MCB_FUNCS
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
// initDetector();
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
// testFpga();
// testRAM();
// printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG));
//moench specific
// setPhaseShiftOnce(); //firmware.h
prepareADC(); // server_funcs
// setPhaseShiftOnce();
/*some registers set, which is in common with jungfrau, please check */
prepareADC();
//setADC(-1); //already does setdaqreg and clean fifo
// setSettings(GET_SETTINGS,-1);
/*some registers set, which is in common with jungfrau, please check */
initDac(0); initDac(8); //initializes the two dacs
//Initialization
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
setFrames(-1);
setTrains(-1);
setExposureTime(-1);
@@ -152,14 +223,24 @@ int init_detector(int b, int checkType) {
setMaster(GET_MASTER);
setSynchronization(GET_SYNCHRONIZATION_MODE);
startReceiver(0); //firmware
}
}//end of control server only--
else printf("\n\n");
//common for both control and stop server
strcpy(mess,"dummy message");
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
lockStatus=0;
// getDynamicRange();
/* both these functions setROI and allocateRAM should go into the control server part. */
if(myDetectorType!=JUNGFRAU){
int retvalsize,ret;
setROI(-1,NULL,&retvalsize,&ret);
allocateRAM();
}
return OK;
}
@@ -182,9 +263,9 @@ int decode_function(int file_des) {
printf("size of data received %d\n",n);
#endif
//#ifdef VERBOSE
#ifdef VERBOSE
printf( "calling function fnum = %d %x %x %x\n",fnum,(unsigned int)(flist[fnum]), (unsigned int)(flist[F_READ_REGISTER]),(unsigned int)(&read_register));
//#endif
#endif
if (fnum<0 || fnum>255)
fnum=255;
retval=(*flist[fnum])(file_des);
@@ -962,7 +1043,6 @@ int set_dac(int file_des) {
int imod;
int n;
int val;
int idac=0;
int mV=0;
sprintf(mess,"Can't set DAC\n");
@@ -999,7 +1079,6 @@ int set_dac(int file_des) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if (ind<16) {
if (mV) {
@@ -1029,21 +1108,13 @@ int set_dac(int file_des) {
}
retval=adcvpp;;
}
} else if (ind==HV_NEW )
retval=initHighVoltageByModule(val,imod);
else
printf("**********No dac with index %d\n",ind);
}
}
if(ret==OK){
/* ret=FAIL; */
/* if(idac==HIGH_VOLTAGE){ */
/* if(retval==-2) */
/* strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200"); */
/* else if(retval==-3) */
/* strcpy(mess,"Weird value read back or it has not been set yet\n"); */
/* else */
/* ret=OK; */
/* }//since v r saving only msb */
/* else if ((retval-val)<=3 || val==-1) */
/* ret=OK; */
if (ind<16) {
if (mV) {
@@ -1052,13 +1123,15 @@ int set_dac(int file_des) {
printf("%d mV \n",retval1);
} else
retval1=retval;
}
} else
retval1=retval;
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
}
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
else{
@@ -1182,9 +1255,9 @@ int set_channel(int file_des) {
if (ret==OK) {
if (myChan.module>=getNModBoard())
ret=FAIL;
if (myChan.chip>=NCHIP)
if (myChan.chip>=N_CHIP)
ret=FAIL;
if (myChan.chan>=NCHAN)
if (myChan.chan>=N_CHAN)
ret=FAIL;
if (myChan.module<0)
myChan.module=ALLMOD;
@@ -1258,13 +1331,13 @@ int get_channel(int file_des) {
}
if (ret==OK) {
ret=FAIL;
if (ichip>=0 && ichip<NCHIP) {
if (ichip>=0 && ichip<N_CHIP) {
ret=OK;
}
}
if (ret==OK) {
ret=FAIL;
if (ichan>=0 && ichan<NCHAN) {
if (ichan>=0 && ichan<N_CHAN) {
ret=OK;
}
}
@@ -1304,12 +1377,12 @@ int get_channel(int file_des) {
int set_chip(int file_des) {
sls_detector_chip myChip;
int ch[NCHAN];
int ch[N_CHAN];
int n, retval;
int ret=OK;
myChip.nchan=NCHAN;
myChip.nchan=N_CHAN;
myChip.chanregs=ch;
@@ -1336,7 +1409,7 @@ int set_chip(int file_des) {
ret=FAIL;
if (myChip.module<0)
myChip.module=ALLMOD;
if (myChip.chip>=NCHIP)
if (myChip.chip>=N_CHIP)
ret=FAIL;
}
if (differentClients==1 && lockStatus==1) {
@@ -1392,7 +1465,7 @@ int get_chip(int file_des) {
}
if (ret==OK) {
ret=FAIL;
if (ichip>=0 && ichip<NCHIP) {
if (ichip>=0 && ichip<N_CHIP) {
ret=OK;
}
}
@@ -1430,17 +1503,24 @@ int get_chip(int file_des) {
}
int set_module(int file_des) {
sls_detector_module myModule;
int *myChip=malloc(NCHIP*sizeof(int));
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
int *myDac=malloc(NDAC*sizeof(int));/**dhanya*/
int *myAdc=malloc(NADC*sizeof(int));/**dhanya*/
int retval, n;
int ret=OK;
int dr;// ow;
int dr;
sls_detector_module myModule;
int *myDac=malloc(N_DAC*sizeof(int));
int *myAdc=malloc(N_ADC*sizeof(int));
int *myChip=NULL;
int *myChan=NULL;
/*not required for jungfrau. so save memory*/
if(myDetectorType != JUNGFRAU){
myChip=malloc(N_CHIP*sizeof(int));
myChan=malloc(N_CHIP*N_CHAN*sizeof(int));
}
dr=setDynamicRange(-1);
dr=setDynamicRange(-1); /* move this down to after initialization?*/
//initialize myModule values
if (myDac)
myModule.dacs=myDac;
else {
@@ -1453,6 +1533,11 @@ int set_module(int file_des) {
sprintf(mess,"could not allocate adcs\n");
ret=FAIL;
}
myModule.chipregs=NULL;
myModule.chanregs=NULL;
/*not required for jungfrau. so save memory*/
if(myDetectorType != JUNGFRAU){
if (myChip)
myModule.chipregs=myChip;
else {
@@ -1465,17 +1550,21 @@ int set_module(int file_des) {
sprintf(mess,"could not allocate chans\n");
ret=FAIL;
}
}
myModule.ndac=NDAC;
myModule.nchip=NCHIP;
myModule.nchan=NCHAN*NCHIP;
myModule.nadc=NADC;
myModule.ndac=N_DAC;
myModule.nchip=N_CHIP;
myModule.nchan=N_CHAN*N_CHIP;
myModule.nadc=N_ADC;
#ifdef VERBOSE
printf("Setting module\n");
#endif
ret=receiveModule(file_des, &myModule);
if(myDetectorType != JUNGFRAU)
ret=receiveModuleGeneral(file_des, &myModule, 1); //1 is to receive everything
else
ret=receiveModuleGeneral(file_des, &myModule, 0); //0 is to receive partially (without trimbits etc.)
if (ret>=0)
ret=OK;
@@ -1503,6 +1592,8 @@ int set_module(int file_des) {
} else {
#ifdef MCB_FUNCS
retval=initModulebyNumber(myModule);
if(retval != myModule.reg)
ret = FAIL;
#endif
}
}
@@ -1522,14 +1613,15 @@ int set_module(int file_des) {
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
}
free(myChip);
free(myChan);
free(myDac);
free(myAdc);
if(myAdc != NULL) free(myAdc);
if(myChip != NULL) free(myChip);
if(myChan != NULL) free(myChan);
//setDynamicRange(dr); always 16 commented out
return ret;
}
@@ -1538,21 +1630,22 @@ int set_module(int file_des) {
int get_module(int file_des) {
int ret=OK;
int arg;
int imod;
int n;
sls_detector_module myModule;
int *myChip=malloc(NCHIP*sizeof(int));
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
int *myDac=malloc(NDAC*sizeof(int));/**dhanya*/
int *myAdc=malloc(NADC*sizeof(int));/**dhanya*/
int *myDac=malloc(N_DAC*sizeof(int));
int *myChip=NULL;
int *myChan=NULL;
int *myAdc=NULL;
/*not required for jungfrau. so save memory*/
if(myDetectorType != JUNGFRAU){
myChip=malloc(N_CHIP*sizeof(int));
myChan=malloc(N_CHIP*N_CHAN*sizeof(int));
myAdc=malloc(N_ADC*sizeof(int));
}
if (myDac)
@@ -1561,6 +1654,13 @@ int get_module(int file_des) {
sprintf(mess,"could not allocate dacs\n");
ret=FAIL;
}
myModule.adcs=NULL;
myModule.chipregs=NULL;
myModule.chanregs=NULL;
/*not required for jungfrau. so save memory*/
if(myDetectorType != JUNGFRAU){
if (myAdc)
myModule.adcs=myAdc;
else {
@@ -1579,13 +1679,12 @@ int get_module(int file_des) {
sprintf(mess,"could not allocate chans\n");
ret=FAIL;
}
}
myModule.ndac=NDAC;
myModule.nchip=NCHIP;
myModule.nchan=NCHAN*NCHIP;
myModule.nadc=NADC;
myModule.ndac=N_DAC;
myModule.nchip=N_CHIP;
myModule.nchan=N_CHAN*N_CHIP;
myModule.nadc=N_ADC;
@@ -1619,17 +1718,18 @@ int get_module(int file_des) {
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
ret=sendModule(file_des, &myModule);
if(myDetectorType != JUNGFRAU)
ret=sendModuleGeneral(file_des, &myModule,1); //1 is to send everything
else
ret=sendModuleGeneral(file_des, &myModule,0); //0 is to send partially (without trimbits etc.)
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
}
free(myChip);
free(myChan);
free(myDac);
free(myAdc);
if(myChip != NULL) free(myChip);
if(myChan != NULL) free(myChan);
if(myAdc != NULL) free(myAdc);
/*return ok/fail*/
@@ -1854,7 +1954,35 @@ int get_run_status(int file_des) {
retval= runState();
printf("\n\nSTATUS=%08x\n",retval);
if(myDetectorType == JUNGFRAU){
if(!(retval&RUN_BUSY_BIT)){
if((retval&READMACHINE_BUSY_BIT) ){
printf("-----------------------------------READ MACHINE BUSY--------------------------\n");
s=TRANSMITTING;
}
//and readbusy=0,idle
else if((!(retval&0xffff))||(retval==SOME_FIFO_FULL_BIT)){
printf("-----------------------------------IDLE--------------------------------------\n");
s=IDLE;
} else {
printf("-----------------------------------Unknown status %08x--------------------------------------\n", retval);
s=ERROR;
ret=FAIL;
}
}
//if runbusy=1
else {
if (retval&WAITING_FOR_TRIGGER_BIT){
printf("-----------------------------------WAITING-----------------------------------\n");
s=WAITING;
}
else{
printf("-----------------------------------RUNNING-----------------------------------\n");
s=RUNNING;
}
}
}else{
//error
if(retval&SOME_FIFO_FULL_BIT){
printf("-----------------------------------ERROR--------------------------------------x%0x\n",retval);
@@ -1864,10 +1992,13 @@ int get_run_status(int file_des) {
// else if(!(retval&RUNMACHINE_BUSY_BIT)){ //commented by Anna 24.10.2012
else if(!(retval&RUN_BUSY_BIT)){ // by Anna 24.10.2012
if((retval&STOPPED_BIT) ){ //
//and readbusy=1, its last frame read
if((retval&READMACHINE_BUSY_BIT) ){ //
printf("-----------------------------------STOPPED--------------------------\n");
s=STOPPED;
} else if((retval&READMACHINE_BUSY_BIT) ){ // ///and readbusy=1, its last frame read
printf("-----------------------------------READ MACHINE BUSY--------------------------\n");
@@ -1900,7 +2031,7 @@ int get_run_status(int file_des) {
}
}
}
if (ret!=OK) {
@@ -1924,14 +2055,12 @@ 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);
printf("Warning: %s\n",mess);
sendDataOnly(file_des,&dataret,sizeof(dataret));
sendDataOnly(file_des,mess,sizeof(mess));
#ifdef VERBOSE
@@ -1940,6 +2069,7 @@ int read_frame(int file_des) {
return dataret;
}
p=fifo_read_frame();
if (p) {
nframes++;
@@ -1971,6 +2101,10 @@ int read_frame(int file_des) {
sendDataOnly(file_des,&dataret,sizeof(dataret));
sendDataOnly(file_des,mess,sizeof(mess));
}
return dataret;
}
@@ -2288,55 +2422,50 @@ int set_roi(int file_des) {
int retvalsize=0;
ROI arg[MAX_ROIS];
ROI* retval=0;
int iroi;
strcpy(mess,"Could not set/get roi\n");
// u_int32_t disable_reg=0;
n = receiveDataOnly(file_des,&nroi,sizeof(nroi));
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
ret=FAIL;
}
if(myDetectorType == JUNGFRAU){
ret = FAIL;
strcpy(mess,"Not applicable/implemented for this detector\n");
printf("Error:Set ROI-%s",mess);
}
else{
if(nroi>=0){
n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI));
if (n != (nroi*sizeof(ROI))) {
sprintf(mess,"Received wrong number of bytes for ROI\n");
ret=FAIL;
}
//#ifdef VERBOSE
printf("Setting ROI to:");
for( i=0;i<nroi;i++)
printf("%d\t%d\t%d\t%d\n",arg[i].xmin,arg[i].xmax,arg[i].ymin,arg[i].ymax);
//
printf("Error: Function 41 or Setting ROI is not yet implemented in Moench!\n");
//#endif
}
/* execute action if the arguments correctly arrived*/
if (lockStatus==1 && differentClients==1){//necessary???
sprintf(mess,"Detector locked by %s\n", lastClientIP);
ret=FAIL;
}
else{
retval=setROI(nroi,arg,&retvalsize,&ret);
if (ret==FAIL){
printf("mess:%s\n",mess);
sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize);
}
}
}
if(ret==OK && differentClients){
@@ -2490,7 +2619,6 @@ int set_speed(int file_des) {
int set_readout_flags(int file_des) {
enum readOutFlags arg;
int n;
int ret=FAIL;
@@ -2785,7 +2913,7 @@ int load_image(int file_des) {
int ret=OK;
int n;
enum imageType index;
short int ImageVals[NCHAN*NCHIP];
short int ImageVals[N_CHAN*N_CHIP];
sprintf(mess,"Loading image failed\n");
@@ -2950,7 +3078,7 @@ int read_counter_block(int file_des) {
int n;
int startACQ;
//char *retval=NULL;
short int CounterVals[NCHAN*NCHIP];
short int CounterVals[N_CHAN*N_CHIP];
sprintf(mess,"Read counter block failed\n");
@@ -3319,7 +3447,6 @@ int write_adc_register(int file_des) {
int arg[2];
int addr, val;
int n;
u_int32_t address;
sprintf(mess,"Can't write to register\n");

View File

@@ -69,7 +69,6 @@ int set_dynamic_range(int);
int set_roi(int);
int get_roi(int);
int set_speed(int);
void prepareADC(void);
int set_readout_flags(int);
int execute_trimming(int);
int lock_server(int);

View File

@@ -1,749 +0,0 @@
#ifndef PICASSOD
#include "server_defs.h"
#else
#include "picasso_defs.h"
#endif
#include "trimming_funcs.h"
#include "mcb_funcs.h"
#include "firmware_funcs.h"
#include <math.h>
extern int nModX;
//extern int *values;
extern const int nChans;
extern const int nChips;
extern const int nDacs;
extern const int nAdcs;
int trim_fixed_settings(int countlim, int par2, int im)
{
int retval=OK;
#ifdef VERBOSE
printf("Trimming with fixed settings\n");
#endif
#ifdef VIRTUAL
return OK;
#endif
if (par2<=0)
retval=trim_with_level(countlim, im);
else
retval=trim_with_median(countlim,im);
return retval;
}
int trim_with_noise(int countlim, int nsigma, int im)
{
int retval=OK, retval1=OK, retval2=OK;
#ifdef VERBOSE
printf("Trimming using noise\n");
#endif
#ifdef VIRTUAL
return OK;
#endif
/* threshold scan */
#ifdef VERBOSE
printf("chosing vthresh and vtrim.....");
#endif
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
#ifdef VERBOSE
printf("trimming with noise.....\n");
#endif
retval2=trim_with_level(countlim, im);
#ifdef DEBUGOUT
printf("done\n");
#endif
if (retval1==OK && retval2==OK)
retval=OK;
else
retval=FAIL;
return retval;
}
int trim_with_beam(int countlim, int nsigma, int im) //rpc
{
int retval=OK, retval1=OK, retval2=OK;
printf("Trimming using beam\n");
//return OK;
#ifdef VIRTUAL
printf("Trimming using beam\n");
return OK;
#endif
/* threshold scan */
#ifdef DEBUGOUT
printf("chosing vthresh and vtrim.....");
#endif
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
retval2=trim_with_median(TRIM_DR, im);
#ifdef DEBUGOUT
printf("done\n");
#endif
if (retval1==OK && retval2==OK)
retval=OK;
else
retval=FAIL;
return retval;
}
int trim_improve(int maxit, int par2, int im) //rpc
{
int retval=OK, retval1=OK, retval2=OK;
#ifdef VERBOSE
printf("Improve the trimming\n");
#endif
#ifdef VIRTUAL
return OK;
#endif
if (par2!=0 && im==ALLMOD)
retval1=choose_vthresh();
retval2=trim_with_median(2*maxit+1, im);
#ifdef DEBUGOUT
printf("done\n");
#endif
if (retval1==OK && retval2==OK)
retval=OK;
else
retval=FAIL;
return retval;
}
int calcthr_from_vcal(int vcal) {
int thrmin;
//thrmin=140+3*vcal/5;
thrmin=180+3*vcal/5;
return thrmin;
}
int calccal_from_vthr(int vthr) {
int vcal;
vcal=5*(vthr-140)/3;
return vcal;
}
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
int retval=OK;
#ifdef MCB_FUNCS
int modma, modmi, nm;
int thr, thrstep=5, nthr=31;
int *fifodata;
double vthreshmean, vthreshSTDev;
int *thrmi, *thrma;
double c;
double b=BVTRIM;
double a=AVTRIM;
int *trim;
int ich, imod, ichan;
int nvalid=0;
u_int32_t *scan;
int ithr;
sls_detector_channel myChan;
setFrames(1);
// setNMod(getNModBoard());
if (im==ALLMOD){
modmi=0;
modma=nModX;
} else {
modmi=im;
modma=im+1;
}
nm=modma-modmi;
trim=malloc(sizeof(int)*nChans*nChips*nModX);
thrmi=malloc(sizeof(int)*nModX);
thrma=malloc(sizeof(int)*nModX);
for (ich=0; ich<nChans*nChips*nm; ich++)
trim[ich]=-1;
/*
setCSregister(im);
setSSregister(im);
initChannel(0,0,0,1,0,0,im);
counterClear(im);
clearSSregister(im);
usleep(500);
*/
myChan.chan=-1;
myChan.chip=-1;
myChan.module=ALLMOD;
myChan.reg=COMPARATOR_ENABLE;
initChannelbyNumber(myChan);
for (ithr=0; ithr<nthr; ithr++) {
fifoReset();
/* scanning threshold */
for (imod=modmi; imod<modma; imod++) {
//commented out by dhanya thr=getDACbyIndexDACU(VTHRESH,imod);
if (ithr==0) {
thrmi[imod]=thr;
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
} else
;//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
}
/* setCSregister(ALLMOD);
setSSregister(ALLMOD);
initChannel(0,0,0,1,0,0,im);
setDynamicRange(32);
*/
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
}
usleep(500);
fifodata=fifo_read_event(0);
scan=decode_data(fifodata);
for (imod=modmi; imod<modma; imod++) {
for (ichan=0; ichan<nChans*nChips; ichan++){
ich=imod*nChips*nChans+ichan;
if (scan[ich]>countlim && trim[ich]==-1) {
//commented out by dhanya trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
#ifdef VERBOSE
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
#endif
}
#ifdef VERBOSE
/* else {
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
}*/
#endif
}
}
free(scan);
}
for (imod=modmi; imod<modma; imod++) {
vthreshmean=0;
vthreshSTDev=0;
nvalid=0;
//commented out by dhanya thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
for (ichan=0; ichan<nChans*nChips; ichan++){
ich=imod*nChans*nChips+ichan;
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
vthreshmean=vthreshmean+trim[ich];
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
nvalid++;
}
}
if (nvalid>0) {
vthreshmean=vthreshmean/nvalid;
//commented out by dhanya vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean);
} else {
vthreshmean=thrmi[imod];
vthreshSTDev=nthr*thrstep;
printf("No valid channel for module %d\n",imod);
retval=FAIL;
}
#ifdef DEBUGOUT
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
#endif
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
if (thr<0 || thr>(DAC_DR-1)) {
thr=thrmi[imod]/2;
printf("Can't find correct threshold for module %d\n",imod);
retval=FAIL;
}
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
#ifdef VERBOSE
printf("vthresh=%d \n",thr);
#endif
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
//commented out by dhanya thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a));
if (thr<500 || thr>(DAC_DR-1)) {
thr=750;
printf("Can't find correct trimbit size for module %d\n",imod);
retval=FAIL;
}
//commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod);
#ifdef VERBOSE
printf("vtrim=%d \n",thr);
#endif
}
free(trim);
free(thrmi);
free(thrma);
#endif
return retval;
}
int trim_with_level(int countlim, int im) {
int ich, itrim, ichan, ichip, imod;
u_int32_t *scan;
int *inttrim;
int modma, modmi, nm;
int retval=OK;
int *fifodata;
sls_detector_channel myChan;
printf("trimming module number %d", im);
#ifdef MCB_FUNCS
setFrames(1);
// setNMod(getNModBoard());
if (im==ALLMOD){
modmi=0;
modma=nModX;
} else {
modmi=im;
modma=im+1;
}
nm=modma-modmi;
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
printf("countlim=%d\n",countlim);
for (ich=0; ich<nChans*nChips*nModX; ich++)
inttrim[ich]=-1;
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
fifoReset();
printf("Trimbit %d\n",itrim);
myChan.chan=-1;
myChan.chip=-1;
myChan.module=ALLMOD;
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
initChannelbyNumber(myChan);
/*
setCSregister(im);
setSSregister(im);
initChannel(itrim,0,0,1,0,0,ALLMOD);
setDynamicRange(32);
*/
setCSregister(ALLMOD);
setSSregister(ALLMOD);
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
}
usleep(500);
fifodata=fifo_read_event(0);
scan=decode_data(fifodata);
for (imod=modmi; imod<modma; imod++) {
for (ichan=0; ichan<nChans*nChips; ichan++) {
ich=ichan+imod*nChans*nChips;
if (inttrim[ich]==-1) {
if (scan[ich]>countlim){
inttrim[ich]=itrim;
if (scan[ich]>2*countlim && itrim>0) {
//if (scan[ich]>2*countlim || itrim==0) {
inttrim[ich]=itrim-1;
}
#ifdef VERBOSE
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
#endif
}
}
#ifdef VERBOSE
/* else
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
#endif
}
}
free(scan);
}
for (imod=modmi; imod<modma; imod++) {
clearCSregister(imod);
firstChip(im);
for (ichip=0; ichip<nChips; ichip++) {
clearSSregister(imod);
for (ichan=0; ichan<nChans; ichan++) {
nextStrip(imod);
ich=ichan+imod*nChans*nChips+ichip*nChans;
if (*(inttrim+ich)==-1) {
*(inttrim+ich)=TRIM_DR;
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
retval=FAIL;
}
#ifdef VERBOSE
// else
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
#endif
initChannel(inttrim[ich],0,0,1,0,0,imod);
}
nextChip(imod);
}
}
free(inttrim);
#endif
return retval;
}
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
int kth_smallest(int *a, int n, int k)
{
register int i,j,l,m ;
register double x ;
l=0 ; m=n-1 ;
while (l<m) {
x=a[k] ;
i=l ;
j=m ;
do {
while (a[i]<x) i++ ;
while (x<a[j]) j-- ;
if (i<=j) {
ELEM_SWAP(a[i],a[j]) ;
i++ ; j-- ;
}
} while (i<=j) ;
if (j<k) l=i ;
if (k<i) m=j ;
}
return a[k] ;
}
int ave(int *a, int n)
{
int av=0,i;
for (i=0; i<n; i++)
av=av+((double)*(a+i))/((double)n);
return av;
}
int choose_vthresh() {
int retval=OK;
#ifdef MCB_FUNCS
int imod, ichan;
u_int32_t *scan, *scan1;
int olddiff[nModX], direction[nModX];
int med[nModX], med1[nModX], diff, media;
int change_flag=1;
int iteration=0;
int maxiterations=10;
int vthreshmean=0;
int vthresh;
int im=ALLMOD;
int modma, modmi, nm;
int *fifodata;
setFrames(1);
// setNMod(getNModBoard());
if (im==ALLMOD){
modmi=0;
modma=nModX;
} else {
modmi=im;
modma=im+1;
}
nm=modma-modmi;
setDynamicRange(32);
setCSregister(ALLMOD);
setSSregister(ALLMOD);
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
//printf(".");
}
usleep(500);
fifodata=fifo_read_event(0);
scan=decode_data(fifodata);
//
scan1=decode_data(fifodata);
for (imod=modmi; imod<modma; imod++) {
//
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
med1[imod]=med[imod];
//commented out by dhanya vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
olddiff[imod]=0xffffff;
direction[imod]=0;
printf("Median of module %d=%d\n",imod,med[imod]);
}
vthreshmean=vthreshmean/nm;
//media=median(scan,nChans*nChips*nModX);
//printf("Median overall=%d\n",media);
media=median(med1+modmi,nm);
printf("Median of modules=%d\n",media);
free(scan);
free(scan1);
while(change_flag && iteration<maxiterations) {
setDynamicRange(32);
fifoReset();
setCSregister(ALLMOD);
setSSregister(ALLMOD);
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
}
usleep(500);
fifodata=fifo_read_event(0);
scan=decode_data(fifodata);
//
scan1=decode_data(fifodata);
change_flag=0;
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
for (ichan=modmi; ichan<modma; ichan++) {
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
med1[imod]=med[imod];
media=median(med1+modmi,nm);
diff=med[ichan]-media;
if (direction[ichan]==0) {
if (diff>0)
direction[ichan]=1;
else
direction[ichan]=-1;
}
//commented out by dhanya vthresh=getDACbyIndexDACU(VTHRESH,imod);
if ( direction[ichan]!=-3) {
if (abs(diff)>abs(olddiff[ichan])) {
vthresh=vthresh-direction[ichan];
if (vthresh>(DAC_DR-1)) {
vthresh=(DAC_DR-1);
printf("can't equalize threshold for module %d\n", ichan);
retval=FAIL;
}
if (vthresh<0) {
vthresh=0;
printf("can't equalize threshold for module %d\n", ichan);
retval=FAIL;
}
direction[ichan]=-3;
} else {
vthresh=vthresh+direction[ichan];
olddiff[ichan]=diff;
change_flag=1;
}
//commented out by dhanya initDACbyIndex(VTHRESH,vthresh, ichan);
}
}
iteration++;
free(scan);
free(scan1);
}
#endif
return retval;
}
int trim_with_median(int stop, int im) {
int retval=OK;
#ifdef MCB_FUNCS
int ichan, imod, ichip, ich;
u_int32_t *scan, *scan1;
int *olddiff, *direction;
int med, diff;
int change_flag=1;
int iteration=0;
int me[nModX], me1[nModX];
int modma, modmi, nm;
int trim;
int *fifodata;
setFrames(1);
// setNMod(getNModBoard());
if (im==ALLMOD){
modmi=0;
modma=nModX;
} else {
modmi=im;
modma=im+1;
}
nm=modma-modmi;
olddiff=malloc(4*nModX*nChips*nChans);
direction=malloc(4*nModX*nChips*nChans);
for (imod=modmi; imod<modma; imod++) {
for (ichip=0; ichip<nChips; ichip++) {
for (ich=0; ich<nChans; ich++) {
ichan=imod*nChips*nChans+ichip*nChans+ich;
direction[ichan]=0;
olddiff[ichan]=0x0fffffff;
}
}
}
/********
fifoReset();
setCSregister(ALLMOD);
setSSregister(ALLMOD);
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
}
usleep(500);
scan=decode_data(fifo_read_event());
for (imod=modmi; imod<modma; imod++) {
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
printf("Median of module %d=%d\n",imod,me[imod]);
}
med=median(me,nm);
printf("median is %d\n",med);
free(scan);
**************/
while(change_flag && iteration<stop) {
setDynamicRange(32);
fifoReset();
setCSregister(ALLMOD);
setSSregister(ALLMOD);
counterClear(ALLMOD);
clearSSregister(ALLMOD);
usleep(500);
startStateMachine();
while (runBusy()) {
}
usleep(500);
fifodata=fifo_read_event(0);
scan=decode_data(fifodata);
scan1=decode_data(fifodata);
/********* calculates median every time ***********/
for (imod=modmi; imod<modma; imod++) {
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
me1[imod]=me[imod];
printf("Median of module %d=%d\n",imod,me[imod]);
}
med=median(me1,nm);
printf("median is %d\n",med);
change_flag=0;
printf("Trimbits iteration %d of %d\n",iteration, stop);
for (imod=modmi; imod<modma; imod++) {
for (ichip=0; ichip<nChips; ichip++) {
selChip(ichip,imod);
clearSSregister(imod);
for (ich=0; ich<nChans; ich++) {
ichan=imod*nChips*nChans+ichip*nChans+ich;
nextStrip(imod);
diff=scan[ichan]-me[imod];
if (direction[ichan]==0) {
if (diff>0) {
direction[ichan]=1;
} else {
direction[ichan]=-1;
}
}
if ( direction[ichan]!=-3) {
if (abs(diff)>abs(olddiff[ichan])) {
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
direction[ichan]=-3;
} else {
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
olddiff[ichan]=diff;
change_flag=1;
}
if (trim>TRIM_DR) {
trim=63;
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
retval=FAIL;
}
if (trim<0) {
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
trim=0;
retval=FAIL;
}
initChannel(trim,0,0,1,0,0,imod);
}
}
}
}
iteration++;
free(scan);
free(scan1);
}
free(olddiff);
free(direction);
#endif
return retval;
}

View File

@@ -1,20 +0,0 @@
#ifndef TRIMMING_FUNCS_H
#define TRIMMING_FUNCS_H
#include "sls_detector_defs.h"
int trim_fixed_settings(int countlim, int par2, int imod);
int trim_with_noise(int countlim, int nsigma, int imod);
int trim_with_beam(int countlim, int nsigma, int imod);
int trim_improve(int maxit, int par2, int imod);
int calcthr_from_vcal(int vcal);
int calccal_from_vthr(int vthr);
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
int choose_vthresh();
int trim_with_level(int countlim, int imod);
int trim_with_median(int stop, int imod);
int calcthr_from_vcal(int vcal);
int calccal_from_vthr(int vthr);
#endif

View File

@@ -1143,6 +1143,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings
}
thisMultiDetector->currentSettings=ret1;
return ret1;
}
@@ -1255,6 +1256,7 @@ int multiSlsDetector::stopAcquisition(){
}
}
*stoppedFlag=1;
setAcquiringFlag(false);
return ret1;
@@ -1628,6 +1630,15 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){
thisMultiDetector->timerValue[index]=ret1;
if (getDetectorsType() == EIGER) {
//if subexptime set, update rate correction in server and update result in multi client
double r;
if((index == SUBFRAME_ACQUISITION_TIME) && (t>=0) && getRateCorrection(r)){
setRateCorrection(r);
}
}
return ret1;
};
@@ -2415,34 +2426,53 @@ int multiSlsDetector::flatFieldCorrect(double* datain, double *errin, double* da
int multiSlsDetector::setRateCorrection(double t){
// double tdead[]=defaultTDead;
if (t==0) {
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
} else {
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
detectors[idet]->setRateCorrection(t);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
if (getDetectorsType() == MYTHEN){
#ifdef VERBOSE
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
#endif
if (t==0) {
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
} else
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
}
int ret, ret1=-100;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret=detectors[idet]->setRateCorrection(t);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret1==-100)
ret1=ret;
else if (ret!=ret1)
ret1=-1;
}
}
if (getDetectorsType() != MYTHEN){
if (ret1==0)
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
else
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
}
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
}
int multiSlsDetector::getRateCorrection(double &t){
if (getDetectorsType() != MYTHEN){
t = getRateCorrectionTau();
return getRateCorrection();
}
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
#ifdef VERBOSE
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
#endif
//which t should we return if they are all different?
return 1;
} else
t=0;
@@ -2455,21 +2485,35 @@ int multiSlsDetector::getRateCorrection(double &t){
double multiSlsDetector::getRateCorrectionTau(){
double ret1=-100,ret;
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
#ifdef VERBOSE
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
#endif
//which t should we return if they are all different?
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret=detectors[idet]->getRateCorrectionTau();
if (ret1==-100)
ret1=ret;
else if (ret!=ret1)
ret1=-1;
else if (ret!=ret1){
std::cout<< "Rate correction is different for different readouts " << std::endl;
if(getDetectorsType() == EIGER)
ret1=-2;
else
ret1=-1; //same settings also return -1
}
}
}
if (getDetectorsType() != MYTHEN){
//if set by the slsDetector
if(ret1 == 0)
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
else
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
return ret1;
}
//only mythen
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
#ifdef VERBOSE
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
#endif
} else {
#ifdef VERBOSE
std::cout<< "Rate correction is disabled " << std::endl;
@@ -4617,7 +4661,6 @@ int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex
acquisitionIndex = -1;
return NULL;
}
int n,complete=OK;
int i,k,offsetX, offsetY, maxX, maxY; double dr;
int* retval=new int[nel];

View File

@@ -72,6 +72,14 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
ng=0;
no=0;
break;
case JUNGFRAU:
nch=256*256;
nm=1; //modules/detector
nc=8; //chips
nd=16; //dacs+adcs
ng=0;
no=0;
break;
case JUNGFRAUCTB:
nch=32;
nm=1; //modules/detector
@@ -612,6 +620,19 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16;
break;
case JUNGFRAU:
thisDetector->nChan[X]=256;
thisDetector->nChan[Y]=256;
thisDetector->nChip[X]=4;
thisDetector->nChip[Y]=2;
thisDetector->nDacs=16;
thisDetector->nAdcs=0;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16;
break;
case JUNGFRAUCTB:
thisDetector->nChan[X]=32;
thisDetector->nChan[Y]=1;
@@ -837,6 +858,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
setFramesPerFile(MAX_FRAMES_PER_FILE);
if (thisDetector->myDetectorType==MOENCH)
setFramesPerFile(MOENCH_MAX_FRAMES_PER_FILE);
if (thisDetector->myDetectorType==JUNGFRAU)
setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE);
if (thisDetector->myDetectorType==JUNGFRAUCTB)
setFramesPerFile(JFCTB_MAX_FRAMES_PER_FILE);
thisReceiver = new receiverInterface(dataSocket);
@@ -972,6 +995,13 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t)
nd=8; //dacs
na=1;
break;
case JUNGFRAU:
nch=256*256;//32;
nm=1;
nc=4*2;
nd=16; // dacs+adcs
na=0;
break;
case JUNGFRAUCTB:
nch=32;//32;
nm=1;
@@ -1054,16 +1084,20 @@ int slsDetector::sendModule(sls_detector_module *myMod) {
ts+=controlSocket->SendDataOnly(&(myMod->reg),sizeof(myMod->reg));
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(myMod->ndac));
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc));
if(thisDetector->myDetectorType != JUNGFRAU){
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip));
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan));
}
ts+=controlSocket->SendDataOnly(&(myMod->gain),sizeof(myMod->gain));
ts+=controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset));
ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc));
if(thisDetector->myDetectorType != JUNGFRAU){
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
}
return ts;
}
@@ -1118,8 +1152,11 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
ts+=controlSocket->ReceiveDataOnly(&(myMod->reg),sizeof(myMod->reg));
ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(myMod->ndac));
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc));
if(thisDetector->myDetectorType != JUNGFRAU){
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip));
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan));
}
ts+=controlSocket->ReceiveDataOnly(&(myMod->gain), sizeof(myMod->gain));
ts+=controlSocket->ReceiveDataOnly(&(myMod->offset), sizeof(myMod->offset));
@@ -1140,6 +1177,8 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
#ifdef VERBOSE
std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl;
#endif
if(thisDetector->myDetectorType != JUNGFRAU){
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
#ifdef VERBOSE
std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl;
@@ -1148,9 +1187,10 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
#ifdef VERBOSE
std::cout<< "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips;
std::cout<< "mod - nchans= " << myMod->nchan << " nchips= " <<myMod->nchip;
std::cout<< "received chans " << myMod->module << " of size "<< ts << std::endl;
#endif
}
#ifdef VERBOSE
std::cout<< "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << std::endl;
#endif
@@ -2176,6 +2216,11 @@ dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod){
int ret=FAIL;
char mess[100];
int arg[3];
if ( (thisDetector->myDetectorType != GOTTHARD) && (thisDetector->myDetectorType != PROPIX) && index==HV_POT)
index=HV_NEW;
arg[0]=index;
arg[1]=imod;
arg[2]=mV;
@@ -2618,6 +2663,7 @@ int slsDetector::setModule(int reg, int imod){
sls_detector_module myModule;
int* g=0;
int* o=0;
int* iod=0;
#ifdef VERBOSE
std::cout << "slsDetector set module " << std::endl;
@@ -2686,14 +2732,14 @@ int slsDetector::setModule(int reg, int imod){
ads[i]=-1;
myModule.adcs=ads;
}
ret=setModule(myModule,g,o);
ret=setModule(myModule,g,o,iod);
}
return ret;
};
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval){
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval, int* iodelay){
int fnum=F_SET_MODULE;
int retval;
@@ -2717,6 +2763,8 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain);
if((thisDetector->nOffset) && (offsetval))
controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
if(thisDetector->myDetectorType == EIGER)
controlSocket->SendDataOnly(iodelay,sizeof(int));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL) {
@@ -2731,6 +2779,13 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
}
}
if(ret == FAIL && thisDetector->myDetectorType == EIGER && strcasestr(mess,"Rate")){
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
if(strcasestr(mess,"tau/subexptime"))
setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE));
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
thisDetector->tDead = 0;
}
if (ret!=FAIL) {
if (detectorModules) {
@@ -2744,6 +2799,7 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
thisDetector->nDacs=module.ndac;
thisDetector->nAdcs=module.nadc;
if(thisDetector->myDetectorType != JUNGFRAU){
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip];
@@ -2754,14 +2810,16 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
}
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=module.dacs[i];
}
if (adcs) {
for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=module.adcs[i];
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=module.dacs[i];
}
(detectorModules+imod)->gain=module.gain;
(detectorModules+imod)->offset=module.offset;
@@ -2869,6 +2927,7 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){
thisDetector->nDacs=myMod->ndac;
thisDetector->nAdcs=myMod->nadc;
if(thisDetector->myDetectorType != JUNGFRAU){
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
@@ -2879,15 +2938,17 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){
}
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
}
if (adcs) {
for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
}
(detectorModules+imod)->gain=myMod->gain;
(detectorModules+imod)->offset=myMod->offset;
(detectorModules+imod)->serialnumber=myMod->serialnumber;
@@ -3063,10 +3124,13 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
string ssettings;
int* gainval=0, *offsetval=0;
int* iodelay=0;
if(thisDetector->nGain)
gainval=new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval=new int[thisDetector->nOffset];
if(thisDetector->myDetectorType == EIGER)
iodelay = new int;
int ret=0;
@@ -3098,6 +3162,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
case DYNAMICGAIN:
if ((thisDetector->myDetectorType == GOTTHARD) ||
(thisDetector->myDetectorType == PROPIX) ||
(thisDetector->myDetectorType == JUNGFRAU) ||
(thisDetector->myDetectorType == MOENCH)) {
ssettings="/dynamicgain";
thisDetector->currentSettings=DYNAMICGAIN;
@@ -3130,6 +3195,36 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
break;
case LOWNOISE:
break;
case DYNAMICHG0:
if (thisDetector->myDetectorType == JUNGFRAU) {
ssettings="/dynamichg0";
thisDetector->currentSettings=DYNAMICHG0;
}
break;
case FIXGAIN1:
if (thisDetector->myDetectorType == JUNGFRAU) {
ssettings="/fixgain1";
thisDetector->currentSettings=FIXGAIN1;
}
break;
case FIXGAIN2:
if (thisDetector->myDetectorType == JUNGFRAU) {
ssettings="/fixgain2";
thisDetector->currentSettings=FIXGAIN2;
}
break;
case FORCESWITCHG1:
if (thisDetector->myDetectorType == JUNGFRAU) {
ssettings="/forceswitchg1";
thisDetector->currentSettings=FORCESWITCHG1;
}
break;
case FORCESWITCHG2:
if (thisDetector->myDetectorType == JUNGFRAU) {
ssettings="/forceswitchg2";
thisDetector->currentSettings=FORCESWITCHG2;
}
break;
default:
break;
}
@@ -3164,6 +3259,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
case MOENCH:
case GOTTHARD:
case PROPIX:
case JUNGFRAU:
case JUNGFRAUCTB:
//settings is saved in myMod.reg
myMod->reg=thisDetector->currentSettings;
@@ -3184,13 +3280,14 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
#ifdef VERBOSE
cout << "the settings file name is "<<settingsfname << endl;
#endif
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
//if it didnt open, try default settings file
ostringstream ostfn_default;
switch(thisDetector->myDetectorType){
case MOENCH:
case GOTTHARD:
case PROPIX:
case JUNGFRAU:
case JUNGFRAUCTB:
ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".settings";
break;
@@ -3203,7 +3300,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
#ifdef VERBOSE
cout << settingsfname << endl;
#endif
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
//if default doesnt work, return error
std::cout << "Could not open settings file" << endl;
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
@@ -3248,7 +3345,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
}
//if everything worked, set module****
setModule(*myMod,gainval,offsetval);
setModule(*myMod,gainval,offsetval,iodelay);
}
}
@@ -3342,6 +3439,7 @@ int slsDetector::updateDetectorNoWait() {
if((thisDetector->myDetectorType!= GOTTHARD)&&
(thisDetector->myDetectorType!= PROPIX)&&
(thisDetector->myDetectorType!= JUNGFRAU)&&
(thisDetector->myDetectorType!= MOENCH)){
//thr=getThresholdEnergy();
n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr));
@@ -3600,7 +3698,7 @@ int* slsDetector::getDataFromDetector(int *retval){
std::cout<< "Received "<< n << " data bytes" << std::endl;
#endif
if (n!=thisDetector->dataBytes) {
std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
thisDetector->stoppedFlag=1;
ret=FAIL;
if (r==NULL) {
@@ -3821,6 +3919,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
thisDetector->timerValue[index]=t;
if((thisDetector->myDetectorType==GOTTHARD)||
(thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)||
(thisDetector->myDetectorType==MOENCH))
thisDetector->timerValue[PROBES_NUMBER]=0;
}
@@ -3845,30 +3944,27 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//send acquisiton period/frame number to receiver
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD))
{
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
if(ret != FAIL){
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
int64_t args[2];
args[1] = retval;
if(t == -1)
args[1] = -1;
if(t == -1) args[1] = -1;
if(index==FRAME_NUMBER){
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
#ifdef VERBOSE
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
#endif
args[0] = FRAME_NUMBER;
retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]);
if(args[1] != -1) args[1]=retval;
}else{
#ifdef VERBOSE
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
#endif
args[0] = FRAME_PERIOD;
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
if(!retval)
args[1] = timerValue[ACQUISITION_TIME];
if(!retval) args[1] = timerValue[ACQUISITION_TIME];
}
@@ -3884,7 +3980,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
}
}else{
cout << "ERROR:Number of Frames in receiver set incorrectly to " << ut << " instead of " << retval << endl;
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << retval << endl;
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
}
}
@@ -3895,7 +3991,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
}
}
return thisDetector->timerValue[index];
};
int slsDetector::lockServer(int lock) {
@@ -4890,8 +4985,9 @@ int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout
};
int slsDetector::setRateCorrection(double t){
double tdead[]=defaultTDead;
if (getDetectorsType() == MYTHEN){
double tdead[]=defaultTDead;
if (t==0) {
#ifdef VERBOSE
std::cout<< "unsetting rate correction" << std::endl;
@@ -4915,6 +5011,56 @@ int slsDetector::setRateCorrection(double t){
}
int fnum=F_SET_RATE_CORRECT;
int ret=FAIL;
char mess[1000]="";
int64_t arg = t*1e9;
int64_t retval = -1;
#ifdef VERBOSE
std::cout<< "Setting Rate Correction to " << arg << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&arg,sizeof(arg));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL) {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
if(retval<0){
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
thisDetector->tDead = 0;
}else{
if(retval>0){
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
if(t < 0)
thisDetector->tDead = -1;
else
thisDetector->tDead = (double)retval/(double)1e9;
}
else{
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
thisDetector->tDead = (double)retval/(double)1e9;
}
}
} else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
if(strcasestr(mess,"tau/subexptime"))
setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE));
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
thisDetector->tDead = 0;
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
}
int slsDetector::getRateCorrection(double &t){
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
@@ -5948,6 +6094,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
if ((thisDetector->myDetectorType==GOTTHARD)||
(thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)||
(thisDetector->myDetectorType==MOENCH)) {
names[0]= "hostname";
names[1]= "port";
@@ -6019,9 +6166,9 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
int slsDetector::writeSettingsFile(string fname, int imod){
int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod]);
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay);
};
@@ -6032,6 +6179,7 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL;
int* gainval=0; int* offsetval=0;
int *iodelay=0;
if(thisDetector->nGain){
gainval=new int[thisDetector->nGain];
for(int i=0;i<thisDetector->nGain;i++)
@@ -6042,6 +6190,8 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
for(int i=0;i<thisDetector->nOffset;i++)
offsetval[i] = -1;
}
if(thisDetector->myDetectorType == EIGER)
iodelay = new int;*iodelay=0;
string fn=fname;
fn=fname;
int mmin=0, mmax=setNumberOfModules();
@@ -6061,13 +6211,14 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im);
fn=ostfn.str();
}
myMod=readSettingsFile(fn, thisDetector->myDetectorType);
myMod=readSettingsFile(fn, thisDetector->myDetectorType,myMod,iodelay);
if (myMod) {
myMod->module=im;
//settings is saved in myMod.reg for all except mythen
if(thisDetector->myDetectorType!=MYTHEN)
myMod->reg=thisDetector->currentSettings;
setModule(*myMod,gainval,offsetval);
setModule(*myMod,gainval,offsetval,iodelay);
deleteModule(myMod);
if(gainval) delete[] gainval;
if(offsetval) delete[] offsetval;
@@ -6080,9 +6231,9 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
int slsDetector::saveSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL;
int ret=FAIL;
int *iod = 0;
int mmin=0, mmax=setNumberOfModules();
if (imod>=0) {
@@ -6091,12 +6242,17 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
}
for (int im=mmin; im<mmax; im++) {
ostringstream ostfn;
if(thisDetector->myDetectorType == EIGER)
if(thisDetector->myDetectorType == EIGER){
ostfn << fname << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER);
else
} else
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im);
if ((myMod=getModule(im))) {
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod);
if(thisDetector->myDetectorType == EIGER){
iod = new int;
*iod = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1);
}
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod,iod);
deleteModule(myMod);
}
}
@@ -6148,6 +6304,7 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
string fn=fname;
int* gainval=0; int* offsetval=0;
int* iodelay=0;
if(thisDetector->nGain){
gainval=new int[thisDetector->nGain];
for(int i=0;i<thisDetector->nGain;i++)
@@ -6179,7 +6336,8 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
}
fn=ostfn.str();
if((myMod=getModule(im))){
iodelay = new int;
*iodelay = (int)setDAC(-1,IO_DELAY,0);
//extra gain and offset
if(thisDetector->nGain){
if(readCalibrationFile(fn,gainval, offsetval,thisDetector->myDetectorType)==FAIL)
@@ -6189,7 +6347,7 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL)
return FAIL;
}
setModule(*myMod,gainval,offsetval);
setModule(*myMod,gainval,offsetval,iodelay);
deleteModule(myMod);
if(gainval) delete[]gainval;
@@ -6589,7 +6747,7 @@ int slsDetector::startReceiver(){
setErrorMask((getErrorMask())|(COULDNOT_START_RECEIVER));
}
}
if((ret==OK))//&& (thisDetector->myDetectorType != EIGER))
if((ret==OK) && (thisDetector->myDetectorType != JUNGFRAU))
ret=detectorSendToReceiver(true);
return ret;
@@ -6603,7 +6761,7 @@ int slsDetector::stopReceiver(){
int ret = FAIL;
char mess[] = "";
if(thisDetector->myDetectorType != EIGER)
if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU)
detectorSendToReceiver(false);
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
@@ -6781,7 +6939,6 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int
int n;
char mess[100]="Nothing";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
@@ -6814,6 +6971,13 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int
disconnectData();
return NULL;
}
//jungfrau masking adcval
if(thisDetector->myDetectorType == JUNGFRAU){
for(unsigned int i=0;i<nel;i++){
retval[i] = (retval[i] & 0x3FFF3FFF);
}
}
}
disconnectData();
}

View File

@@ -494,11 +494,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
writes a trim/settings file for module number imod - the values will be read from the current detector structure
\param fname name of the file to be written
\param imod module number
\param iodelay io delay (detector specific)
\returns OK or FAIL if the file could not be written
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
*/
using energyConversion::writeSettingsFile;
int writeSettingsFile(string fname, int imod);
int writeSettingsFile(string fname, int imod, int* iodelay=0);
/**
@@ -908,10 +909,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
\param module module to be set - must contain correct module number and also channel and chip registers
\param gainval pointer to extra gain values
\param offsetval pointer to extra offset values
\param iodelay iodelay (detector specific)
\returns current register value
\sa ::sls_detector_module
*/
int setModule(sls_detector_module module, int* gainval, int* offsetval);
int setModule(sls_detector_module module, int* gainval, int* offsetval,int* iodelay);
//virtual int setModule(sls_detector_module module);
/**

View File

@@ -235,6 +235,10 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
*/
virtual int getTotalNumberOfChannels()=0;
/**
\returns total number of channels for each dimension
*/
virtual int getTotalNumberOfChannels(dimension d)=0;
/** generates file name without extension */
virtual string createFileName()=0;
@@ -638,8 +642,10 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
return GET_EXTERNAL_SIGNAL_FLAG ;};
/** returns detector settings string from index
\param s can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS
\returns standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined
\param s can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, LOWNOISE,
DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2, GET_SETTINGS
\returns standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, lownoise,
dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2, undefined
*/
static string getDetectorSettings(detectorSettings s){\
switch(s) { \
@@ -651,12 +657,19 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
case MEDIUMGAIN: return string("mediumgain"); \
case VERYHIGHGAIN: return string("veryhighgain"); \
case LOWNOISE: return string("lownoise"); \
case DYNAMICHG0: return string("dynamichg0"); \
case FIXGAIN1: return string("fixgain1"); \
case FIXGAIN2: return string("fixgain2"); \
case FORCESWITCHG1: return string("forceswitchg1");\
case FORCESWITCHG2: return string("forceswitchg2");\
default: return string("undefined"); \
}};
/** returns detector settings string from index
\param s can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined
\returns setting index STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS
\param s can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, lownoise,
dynamichg0, fixgain1, fixgain2, forceswitchg1, forceswitchg2, undefined
\returns setting index STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN,LOWNOISE,
DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2, GET_SETTINGS
*/
static detectorSettings getDetectorSettings(string s){ \
@@ -668,6 +681,11 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
if (s=="mediumgain") return MEDIUMGAIN; \
if (s=="veryhighgain") return VERYHIGHGAIN; \
if (s=="lownoise") return LOWNOISE; \
if (s=="dynamichg0") return DYNAMICHG0; \
if (s=="fixgain1") return FIXGAIN1; \
if (s=="fixgain2") return FIXGAIN2; \
if (s=="forceswitchg1") return FORCESWITCHG1; \
if (s=="forceswitchg2") return FORCESWITCHG2; \
return GET_SETTINGS; \
};

View File

@@ -163,7 +163,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
i++;
descrToFuncMap[i].m_pFuncName="setctrbit"; //
descrToFuncMap[i].m_pFuncName="resmat"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
i++;
@@ -1113,7 +1113,7 @@ string slsDetectorCommand::helpLine(int narg, char *args[], int action) {
if (narg==0) {
os << "Command can be: " << endl;
for(int i=0; i<numberOfCommands; ++i) {
os << descrToFuncMap[i].m_pFuncName << "\t" ;
os << descrToFuncMap[i].m_pFuncName << "\n" ;
}
os << endl;
return os.str();
@@ -1941,7 +1941,7 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){
}
double t;
if (myDet->getRateCorrection(t)) {
sprintf(answer,"%f",t);
sprintf(answer,"%0.9f",t);
} else {
sprintf(answer,"%f",0.);
}
@@ -1954,7 +1954,7 @@ string slsDetectorCommand::helpRateCorr(int narg, char *args[], int action){
if (action==GET_ACTION || action==HELP_ACTION)
os << string("ratecorr \t returns the dead time used for rate correections in ns \n");
if (action==PUT_ACTION || action==HELP_ACTION)
os << string("ratecorr ns \t sets the deadtime correction constant in ns\n");
os << string("ratecorr ns \t sets the deadtime correction constant in ns, -1 in Eiger will set it to default tau of settings\n");
return os.str();
}
@@ -2247,10 +2247,10 @@ string slsDetectorCommand::cmdCounter(int narg, char *args[], int action){
retval=myDet->resetCounterBlock(ival);
}
else if (string(args[0])==string("setctrbit")){
else if (string(args[0])==string("resmat")){
if (action==PUT_ACTION){
if (!sscanf(args[1],"%d",&ival))
return string("Could not scan resetctrbit input ")+string(args[1]);
return string("Could not scan resmat input ")+string(args[1]);
if(ival>=0)
sprintf(answer,"%d",myDet->setCounterBit(ival));
}else
@@ -2271,12 +2271,12 @@ string slsDetectorCommand::helpCounter(int narg, char *args[], int action){
if (action==PUT_ACTION || action==HELP_ACTION){
os << "readctr \t Cannot put"<< std::endl;
os << "resetctr i \t resets counter in detector, restarts acquisition if i=1"<< std::endl;
os << "setctrbit i \t sets/resets counter bit in detector"<< std::endl;
os << "resmat i \t sets/resets counter bit in detector"<< std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION){
os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1"<< std::endl;
os << "resetctr \t Cannot get"<< std::endl;
os << "setctrbit i \t gets the counter bit in detector"<< std::endl;
os << "resmat i \t gets the counter bit in detector"<< std::endl;
}
return os.str();
}
@@ -3145,7 +3145,8 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) {
ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"<< std::endl;
os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"
"lownoise, dynamichg0,fixgain1,fixgain2,forceswitchg1, forceswitchg2"<< std::endl;
os << "threshold eV\n sets the detector threshold in eV"<< std::endl;
os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl;
os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl;

View File

@@ -110,22 +110,24 @@ int slsDetectorUsers::getPositions(double *pos){
}
int slsDetectorUsers::setDetectorSize(int x0, int y0, int nx, int ny){
if(myDetector->getTotalNumberOfChannels(slsDetectorDefs::Y)>1)
return 1;
int nmod=nx/(myDetector->getChansPerMod(0));
cout << myDetector->getChansPerMod(0) << " " << nx << " " << nmod << endl;
return myDetector->setNumberOfModules(nmod)*myDetector->getChansPerMod(0);}
int slsDetectorUsers::getDetectorSize(int &x0, int &y0, int &nx, int &ny){
y0=0;
ny=1;
x0=0;
nx=myDetector->setNumberOfModules()*myDetector->getChansPerMod(0);
return nx;
nx=myDetector->getTotalNumberOfChannels(slsDetectorDefs::X);
ny=myDetector->getTotalNumberOfChannels(slsDetectorDefs::Y);
return nx*ny;
}
int slsDetectorUsers::getMaximumDetectorSize(int &nx, int &ny){
ny=1;
nx=myDetector->getMaxNumberOfModules()*myDetector->getChansPerMod(0);
return nx;
nx=myDetector->getMaxNumberOfChannelsPerDetector(slsDetectorDefs::X);
ny=myDetector->getMaxNumberOfChannelsPerDetector(slsDetectorDefs::Y);
return nx*ny;
}
int slsDetectorUsers::setBitDepth(int i){

View File

@@ -44,14 +44,12 @@ slsDetectorUtils::slsDetectorUtils() {
int slsDetectorUtils::acquire(int delflag){
//ensure acquire isnt started multiple times by same client
pthread_mutex_lock(&mp);
if(getAcquiringFlag() == false)
setAcquiringFlag(true);
else{
std::cout << "Error: Acquire has already been started." << std::endl;
return FAIL;
}
pthread_mutex_unlock(&mp);
bool receiver = (setReceiverOnline()==ONLINE_FLAG);
@@ -157,10 +155,6 @@ int slsDetectorUtils::acquire(int delflag){
*stoppedFlag=1;
}
//resets frames caught in receiver
resetFramesCaught();
if(setReceiverOnline()==OFFLINE_FLAG)
*stoppedFlag=1;
}
@@ -175,7 +169,10 @@ int slsDetectorUtils::acquire(int delflag){
cout << " starting thread " << endl;
#endif
//resets frames caught in receiver
if(receiver){
resetFramesCaught();
}
for(int im=0;im<nm;im++) {
@@ -183,6 +180,7 @@ int slsDetectorUtils::acquire(int delflag){
cout << " starting measurement "<< im << " of " << nm << endl;
#endif
//cout << "data thread started " << endl;
@@ -364,7 +362,7 @@ int slsDetectorUtils::acquire(int delflag){
usleep(100000);
}*/
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH)){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
@@ -838,6 +836,7 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
break;
case GOTTHARD:
case PROPIX:
case JUNGFRAU:
names[nvar++]="flags";
names[nvar++]="delay";
names[nvar++]="gates";
@@ -922,6 +921,7 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
case MYTHEN:
case GOTTHARD:
case PROPIX:
case JUNGFRAU:
names[nvar++]="flatfield";
names[nvar++]="badchannels";
break;

View File

@@ -421,6 +421,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual int* startAndReadAll()=0;
virtual int getTotalNumberOfChannels()=0;
virtual int getTotalNumberOfChannels(dimension d)=0;
virtual int getMaxNumberOfChannels()=0;
virtual int getMaxNumberOfChannels(dimension d)=0;

View File

@@ -163,7 +163,7 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset,
/* I/O */
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod){
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod, int* iodelay){
@@ -215,6 +215,24 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
break;
case EIGER:
break;
case JUNGFRAU:
names[id++]="VDAC0";
names[id++]="VDAC1";
names[id++]="VDAC2";
names[id++]="VDAC3";
names[id++]="VDAC4";
names[id++]="VDAC5";
names[id++]="VDAC6";
names[id++]="VDAC7";
names[id++]="VDAC8";
names[id++]="VDAC9";
names[id++]="VDAC10";
names[id++]="VDAC11";
names[id++]="VDAC12";
names[id++]="VDAC13";
names[id++]="VDAC14";
names[id++]="VDAC15";
break;
default:
cout << "Unknown detector type - unknown format for settings file" << endl;
return NULL;
@@ -335,10 +353,12 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
infile.open(myfname.c_str(),ifstream::binary);
if (infile.is_open()) {
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
infile.read((char*) iodelay,sizeof(iodelay));
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
#ifdef VERBOSE
for(int i=0;i<myMod->ndac;i++)
std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl;
std::cout << "iodelay:" << *iodelay << std::endl;
#endif
if(infile.eof()){
cout<<endl<<"Error, could not load trimbits end of file, "<<myfname<<", reached."<<endl<<endl;
@@ -359,6 +379,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
case MOENCH:
case GOTTHARD:
case PROPIX:
case JUNGFRAU:
//---------------dacs---------------
infile.open(myfname.c_str(), ios_base::in);
if (infile.is_open()) {
@@ -417,7 +438,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
};
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod){
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay){
ofstream outfile;
@@ -458,6 +479,24 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
break;
case EIGER:
break;
case JUNGFRAU:
names[id++]="VDAC0";
names[id++]="VDAC1";
names[id++]="VDAC2";
names[id++]="VDAC3";
names[id++]="VDAC4";
names[id++]="VDAC5";
names[id++]="VDAC6";
names[id++]="VDAC7";
names[id++]="VDAC8";
names[id++]="VDAC9";
names[id++]="VDAC10";
names[id++]="VDAC11";
names[id++]="VDAC12";
names[id++]="VDAC13";
names[id++]="VDAC14";
names[id++]="VDAC15";
break;
default:
cout << "Unknown detector type - unknown format for settings file" << endl;
return FAIL;
@@ -475,8 +514,10 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
#ifdef VERBOSE
for(int i=0;i<mod.ndac;i++)
std::cout << "dac " << i << ":" << mod.dacs[i] << std::endl;
std::cout << "iodelay: " << *iodelay << std::endl;
#endif
outfile.write((char*)mod.dacs, sizeof(dacs_t)*(mod.ndac));
outfile.write((char*)iodelay, sizeof(iodelay));
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
outfile.close();

View File

@@ -81,21 +81,23 @@ class energyConversion
\param fname name of the file to be read
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
\param iodelay io delay (detector specific)
\returns the pointer to myMod or NULL if reading the file failed
*/
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL);
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL, int* iodelay=0);
/**
writes a trim/settings file
\param fname name of the file to be written
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
\param mod module structure which has to be written to file
\param iodelay io delay (detector specific)
\returns OK or FAIL if the file could not be written
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
*/
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod);
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay=0);
/** allocates the momery for a detector module structure
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)

View File

@@ -137,7 +137,7 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
// 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());
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels()); //only 1d detectors
dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
delete thisData;
fdata=NULL;
@@ -280,7 +280,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);
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);//only 1d detectors
dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
delete thisData;
ang=NULL;
@@ -493,7 +493,8 @@ void* postProcessing::processData(int delflag) {
int currentSubFrameIndex = -1;
bool newData = false;
int nthframe = setReadReceiverFrequency(0);
int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
#ifdef VERBOSE
std::cout << "receiver read freq:" << nthframe << std::endl;
@@ -640,7 +641,7 @@ void* postProcessing::processData(int delflag) {
delete [] receiverData;
if ((fdata) && (dataReady)){
// cout << "DATAREADY 3" << endl;
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,getTotalNumberOfChannels());
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
delete thisData;
fdata = NULL;
@@ -810,7 +811,7 @@ void postProcessing::initDataset(int r) {
}
double tdead;
if (*correctionMask&(1<<RATE_CORRECTION)) {
if ((getDetectorsType()==MYTHEN) && (*correctionMask&(1<<RATE_CORRECTION))) {
#ifdef VERBOSE
cout << "get tau " << endl;
#endif

View File

@@ -51,6 +51,9 @@ int setCounterBit(int val);
int pulsePixel(int n, int x, int y);
int pulsePixelNMove(int n, int x, int y);
int pulseChip(int n);
int setRateCorrection(int64_t custom_tau_in_nsec);
int getRateCorrectionEnable();
int getDefaultSettingsTau_in_nsec();
#endif
#if defined(MYTHEND) || defined(GOTTHARDD)
@@ -67,7 +70,7 @@ int getChip(sls_detector_chip *myChip);
#ifdef EIGERD
int setModule(sls_detector_module myMod, int* gain, int* offset);
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay);
int getModule(sls_detector_module *myMod, int* gain, int* offset);
#else
int setModule(sls_detector_module myMod);

View File

@@ -15,10 +15,17 @@
/* examples*/
#ifdef JUNGFRAU_DHANYA
#define NCHAN (256*256)
#define NCHIP 8
#define NADC 0
#else
#define NCHAN 1
#define NCHIP 1
#define NDAC 1
#define NADC 1
#endif
#define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD NMAXMODX*NMAXMODY
@@ -27,5 +34,4 @@
#endif /* SLSDETECTORSERVER_DEFS_H_ */

View File

@@ -32,6 +32,7 @@ const enum detectorType myDetectorType=PICASSO;
const enum detectorType myDetectorType=GENERIC;
#endif
extern enum detectorSettings thisSettings;
//global variables for optimized readout
char mess[MAX_STR_LENGTH];
@@ -46,7 +47,7 @@ void checkFirmwareCompatibility(){
cprintf(BLUE,"\n\n********************************************************\n"
"**********************EIGER Server**********************\n"
"********************************************************\n");
cprintf(BLUE,"\nFirmware Version: %llx\nSoftware Version: %llx\n\n",
cprintf(BLUE,"\nFirmware Version: %lld\nSoftware Version: %lld\n\n",
getDetectorId(DETECTOR_FIRMWARE_VERSION), getDetectorId(DETECTOR_SOFTWARE_VERSION));
//check for firmware version compatibility
@@ -179,6 +180,7 @@ int function_table() {
flist[F_PULSE_PIXEL]=&pulse_pixel;
flist[F_PULSE_PIXEL_AND_MOVE]=&pulse_pixel_and_move;
flist[F_PULSE_CHIP]=&pulse_chip;
flist[F_SET_RATE_CORRECT]=&rate_correct;
#ifdef VERBOSE
@@ -1791,8 +1793,13 @@ int get_chip(int file_des) {
}
int set_module(int file_des) {
int retval, n,i;
int retval, n;
int ret=OK,ret1=OK;
#ifdef SLS_DETECTOR_FUNCTION_LIST
@@ -1800,6 +1807,7 @@ int set_module(int file_des) {
#ifdef EIGERD
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
int *myIODelay = (int*)malloc(sizeof(int));
#endif
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
@@ -1854,6 +1862,7 @@ int set_module(int file_des) {
#ifdef EIGERD
n = receiveData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
n = receiveData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
n = receiveData(file_des,myIODelay,sizeof(int),INT32);
#endif
if (ret>=0)
ret=OK;
@@ -1861,15 +1870,29 @@ int set_module(int file_des) {
ret=FAIL;
//#ifdef VERBOSE
#ifdef VERBOSE
printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset);
#ifdef EIGERD
int i;
for(i=0;i<getNumberOfGainsPerModule();i++)
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
for(i=0;i<getNumberOfOffsetsPerModule();i++)
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
printf("IO Delay:%d\n",i,*myIODelay);
#endif
//#endif
#endif
switch(myModule.reg){
case STANDARD:
case HIGHGAIN:
case LOWGAIN:
break;
default:
sprintf(mess,"This setting %d does not exist for this detector\n",myModule.reg);
ret = FAIL;
cprintf(RED,"%s",mess);
break;
}
if (ret==OK) {
@@ -1878,7 +1901,26 @@ int set_module(int file_des) {
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
#ifdef EIGERD
ret=setModule(myModule, myGain, myOffset);
ret=setModule(myModule, myGain, myOffset,myIODelay);
//rate correction
if(getRateCorrectionEnable()){
int64_t tau_ns = getDefaultSettingsTau_in_nsec();
if(tau_ns < 0){
sprintf(mess,"Cannot set Rate correction. Rate correction Deactivated, settings %d not recognized by detector\n",thisSettings);
cprintf(RED,"%s",mess);
ret = FAIL;
setRateCorrection(0);
}
retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
if(tau_ns != retval){
if(retval == -1)
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n");
else
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated\n");
cprintf(RED,"%s",mess);
ret = FAIL;
}
}
#else
ret=setModule(myModule);
#endif
@@ -2518,7 +2560,7 @@ int set_timer(int file_des) {
switch(ind) {
#ifdef EIGERD
case SUBFRAME_ACQUISITION_TIME:
if (tns > MAX_SUBFRAME_EXPOSURE_VAL ){
if (tns > (MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS*10) ){
ret=FAIL;
strcpy(mess,"Sub Frame exposure time should not exceed 5.368 seconds\n");
break;
@@ -3815,3 +3857,72 @@ int pulse_chip(int file_des) {
}
int rate_correct(int file_des) {
int64_t tau_ns=-1;
int n;
int64_t retval=-1;
int ret=OK,ret1=OK;
sprintf(mess,"can't set/unset rate correction\n");
n = receiveData(file_des,&tau_ns,sizeof(tau_ns),INT64);
if (n < 0) {
sprintf(mess,"Error reading from socket\n");
cprintf(RED,"%s",mess);
ret=FAIL;
}
#ifndef EIGERD
sprintf(mess,"Rate Correction not implemented for this detector\n");
cprintf(RED,"%s",mess);
ret=FAIL;
#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
//tau = -1, use default tau of settings
if((ret==OK)&&(tau_ns<0)){
tau_ns = getDefaultSettingsTau_in_nsec();
if(tau_ns < 0){
ret = FAIL;
sprintf(mess,"Cannot set rate correction. Settings %d not recognized by detector\n",thisSettings);
cprintf(RED,"%s",mess);
}
}
if (ret==OK) {
printf("Setting rate correction to %lld ns\n",tau_ns);
if (differentClients==1 && lockStatus==1 && tau_ns!=-1) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else {
retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
if(tau_ns != retval){
if(retval == -1)
strcpy(mess,"Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n");
cprintf(RED,"%s",mess);
ret=FAIL;
}
}
}
#endif
if ((ret==OK) && (differentClients))
ret=FORCE_UPDATE;
//ret could be swapped during sendData
ret1 = ret;
n = sendData(file_des,&ret1,sizeof(ret),INT32);
if (ret==FAIL) {
n = sendData(file_des,mess,sizeof(mess),OTHER);
} else {
n = sendData(file_des,&retval,sizeof(retval),INT64);
}
return ret;
}

View File

@@ -87,6 +87,7 @@ int set_counter_bit(int);
int pulse_pixel(int);
int pulse_pixel_and_move(int);
int pulse_chip(int);
int rate_correct(int);
#endif