changes to get index in eiger server

This commit is contained in:
Maliakal Dhanya 2014-11-17 14:46:28 +01:00
parent b24f374155
commit 194b41bfc5
7 changed files with 269 additions and 78 deletions

View File

@ -42,6 +42,7 @@
short Beb_bit_mode; short Beb_bit_mode;
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){ void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){
bebInfo->beb_number=beb_num; bebInfo->beb_number=beb_num;
bebInfo->serial_address=0; bebInfo->serial_address=0;
@ -136,13 +137,14 @@ void Beb_Beb(int arg1){
Beb_SetByteOrder(); Beb_SetByteOrder();
/*
ll_beb_new_memory = &ll_beb_new_memory_local; ll_beb_new_memory = &ll_beb_new_memory_local;
Local_LocalLinkInterface(ll_beb_new_memory); Local_LocalLinkInterface(ll_beb_new_memory);
if(!Local_InitNewMemory(ll_beb_new_memory,XPAR_PLB_LL_NEW_MEMORY, arg1)) if(!Local_InitNewMemory(ll_beb_new_memory,XPAR_PLB_LL_NEW_MEMORY, arg1))
printf("New Memory FAIL\n"); printf("New Memory FAIL\n");
else else
printf("New Memory OK\n"); printf("New Memory OK\n");
*/
} }
@ -156,6 +158,7 @@ void Beb_ClearBebInfos(){
int Beb_InitBebInfos(){//file name at some point int Beb_InitBebInfos(){//file name at some point
Beb_ClearBebInfos(); Beb_ClearBebInfos();
struct BebInfo b0; struct BebInfo b0;
BebInfo_BebInfo(&b0,0); BebInfo_BebInfo(&b0,0);
if(BebInfo_SetSerialAddress(&b0,0xff)) { //all bebs for reset and possibly get request data? if(BebInfo_SetSerialAddress(&b0,0xff)) { //all bebs for reset and possibly get request data?
@ -173,6 +176,7 @@ int Beb_InitBebInfos(){//file name at some point
beb_infos.push_back(b); beb_infos.push_back(b);
*/ */
return Beb_CheckSourceStuffBebInfo(); return Beb_CheckSourceStuffBebInfo();
} }
@ -182,7 +186,7 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac
//so that the values can be reset externally for now.... //so that the values can be reset externally for now....
unsigned int i = Beb_GetBebInfoIndex(beb_number); unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i){ printf("returning 000\n");return 0;} //i must be greater than 0, zero is the global send /******* if(!i) return 0;****************************/ //i must be greater than 0, zero is the global send
BebInfo_SetHeaderInfo(&beb_infos[i],ten_gig,src_mac,src_ip,src_port); BebInfo_SetHeaderInfo(&beb_infos[i],ten_gig,src_mac,src_ip,src_port);
printf("Printing Beb info number (%d) :\n",i); printf("Printing Beb info number (%d) :\n",i);
@ -254,12 +258,13 @@ int Beb_CheckSourceStuffBebInfo(){
} }
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){
if(!beb_numb) return 0; /******************** if(!beb_numb) return 0;******************************/
unsigned int i; unsigned int i;
for(i=1;i<bebInfoSize;i++) for(i=1;i<bebInfoSize;i++)
if(beb_numb==BebInfo_GetBebNumber(&beb_infos[i])) if(beb_numb==BebInfo_GetBebNumber(&beb_infos[i])){
printf("found beb index:%d, for beb number:%d\n",i,beb_numb);
return i; return i;
}
return 0; return 0;
} }
@ -320,7 +325,7 @@ int Beb_SetByteOrder(){
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){ int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){
unsigned int i = Beb_GetBebInfoIndex(beb_number); unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i) return 0; //i must be greater than 0, zero is the global send /***********************************if(!i) return 0; *************************************///i must be greater than 0, zero is the global send
Beb_send_ndata = 14; Beb_send_ndata = 14;
Beb_send_data[0] = ten_gig ? 0x00020000 : 0x00010000; //write to fanout numbers 1 or 2 Beb_send_data[0] = ten_gig ? 0x00020000 : 0x00010000; //write to fanout numbers 1 or 2
@ -337,7 +342,7 @@ int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port){ int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port){
unsigned int i = Beb_GetBebInfoIndex(beb_number); unsigned int i = Beb_GetBebInfoIndex(beb_number);
if(!i) return 0; //i must be greater than 0, zero is the global send /***********************************if(!i) return 0; *************************************///i must be greater than 0, zero is the global send
return Beb_SetHeaderData1(BebInfo_GetSrcMAC(&beb_infos[i],ten_gig),BebInfo_GetSrcIP(&beb_infos[i],ten_gig),BebInfo_GetSrcPort(&beb_infos[i],ten_gig),dst_mac,dst_ip,dst_port); return Beb_SetHeaderData1(BebInfo_GetSrcMAC(&beb_infos[i],ten_gig),BebInfo_GetSrcIP(&beb_infos[i],ten_gig),BebInfo_GetSrcPort(&beb_infos[i],ten_gig),dst_mac,dst_ip,dst_port);
} }

View File

@ -53,7 +53,9 @@ unsigned int Feb_Control_trimbit_size;
unsigned int* Feb_Control_last_downloaded_trimbits; unsigned int* Feb_Control_last_downloaded_trimbits;
int Feb_Control_current_mod;
int Feb_Control_current_index;
int Feb_Control_am_i_master;
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){ void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
unsigned int i; unsigned int i;
@ -142,12 +144,17 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i)
int Feb_Control_IsBottomModule(){ int Feb_Control_IsBottomModule(){
if(Module_BottomAddressIsValid(&modules[1])) if(Module_BottomAddressIsValid(&modules[Feb_Control_current_index]))
return 1; return 1;
return 0; return 0;
} }
int Feb_Control_GetModuleNumber(){
return Feb_Control_current_mod;
}
void Feb_Control_FebControl(){ void Feb_Control_FebControl(){
Feb_Control_staticBits=Feb_Control_acquireNReadoutMode=Feb_Control_triggerMode=Feb_Control_externalEnableMode=Feb_Control_subFrameMode=0; Feb_Control_staticBits=Feb_Control_acquireNReadoutMode=Feb_Control_triggerMode=Feb_Control_externalEnableMode=Feb_Control_subFrameMode=0;
@ -155,6 +162,7 @@ void Feb_Control_FebControl(){
Feb_Control_trimbit_size=263680; Feb_Control_trimbit_size=263680;
Feb_Control_last_downloaded_trimbits = malloc(Feb_Control_trimbit_size * sizeof(int)); Feb_Control_last_downloaded_trimbits = malloc(Feb_Control_trimbit_size * sizeof(int));
/*
printf("\nDefault Settings:\n"); printf("\nDefault Settings:\n");
Feb_Control_nimages = 1; Feb_Control_nimages = 1;
Feb_Control_exposure_time_in_sec = 1; Feb_Control_exposure_time_in_sec = 1;
@ -171,6 +179,23 @@ void Feb_Control_FebControl(){
printf("\n\n"); printf("\n\n");
Feb_Control_Init(); Feb_Control_Init();
*/
/*
unsigned int reg_nums[1];
unsigned int reg_vals[1];
reg_nums[0]=DAQ_REG_CHIP_CMDS;
reg_vals[0]=(0|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),1,reg_nums,reg_vals,0,0)){
printf("Trouble setting them up as slaves\n");;
}
*/
} }
@ -184,36 +209,98 @@ void Feb_Control_ClearModules(){
int Feb_Control_Init(){ int Feb_Control_Init(){
unsigned int i; unsigned int i;
Feb_Control_ClearModules(); Feb_Control_ClearModules();
/*Feb_Control_AddModule(0,0xff);//global send ///*
Feb_Control_current_mod = 0;
Feb_Control_current_index = 0;
Feb_Control_AddModule(0,0xff);//global send
Feb_Control_PrintModuleList();*/ Feb_Control_PrintModuleList();
//*/
Feb_Control_ReadSetUpFileToAddModules("/home/root/executables/setup.txt"); Feb_Control_ReadSetUpFileToAddModules("/home/root/executables/setup.txt");
/*
printf("\nSetting detector defaults:\n"); printf("\nSetting detector defaults:\n");
Feb_Control_ReadSetUpFile(0,"/home/root/executables/setup.txt"); //send defaults to all Feb_Control_ReadSetUpFile(0,"/home/root/executables/setup.txt"); //send defaults to all
for(i=1;i<moduleSize;i++){
/* for(i=1;i<moduleSize;i++){
char st[2000]; char st[2000];
sprintf(st,"setup_mod%04d.txt",Module_GetModuleNumber(&modules[i])); sprintf(st,"setup_mod%04d.txt",Module_GetModuleNumber(&modules[i]));
//Feb_Control_ReadSetUpFile(Module_GetModuleNumber(&modules[i]),st); Feb_Control_ReadSetUpFile(Module_GetModuleNumber(&modules[i]),st);
} }*/
//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_current_mod = (res & 0xFF);
return Feb_Control_CheckSetup(); for(i=1;i<moduleSize;i++){
if(Module_GetModuleNumber(&modules[i])==Feb_Control_current_mod)
Feb_Control_current_index = i;
}
/*Feb_Control_ReadSetUpFile(Feb_Control_current_mod,"/home/root/executables/setup.txt");
printf("Done setting detector defaults\n");*/
Feb_Control_am_i_master = 0;
return 1;
} }
void Feb_Control_Set_Master(){
Feb_Control_am_i_master = 1;
/*
unsigned int halfmastermodule = 0x80000000;
unsigned int reg_nums[1];
unsigned int reg_vals[1];
reg_nums[0]=DAQ_REG_CHIP_CMDS;
reg_vals[0]=(halfmastermodule|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),1,reg_nums,reg_vals,0,0)){
printf("Trouble writing commands....\n");;
return 0;
}
printf("master is set\n");
*/
}
int Feb_Control_ReadSetUpFileToAddModules(char* file_name){ int Feb_Control_ReadSetUpFileToAddModules(char* file_name){
char line[100]; char line[100];
char str[100]; char str[100];
int i0,i1,i2; int i0,i1,i2;
int memaddress = 1;
FILE* fp = fopen(file_name, "r"); FILE* fp = fopen(file_name, "r");
if( fp == NULL ){ if( fp == NULL ){
perror("Error while opening the file.\n"); perror("Error while opening the file.\n");
return 0; return 0;
} }
printf("\nSetting up detector:\n"); printf("\nSetting up detectors:\n");
while ( fgets (line , 255 , fp) != NULL ){ while ( fgets (line , 255 , fp) != NULL ){
if(strlen(line)<=1) if(strlen(line)<=1)
@ -236,29 +323,34 @@ int Feb_Control_ReadSetUpFileToAddModules(char* file_name){
} }
else if(!strcmp(str,"add_half_module")){ else if(!strcmp(str,"add_half_module")){
if( sscanf (line,"%s %d %d", str,&i0,&i1) < 3){ if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){
printf("Error adding half module from %s.\n",file_name); printf("Error adding half module from %s.\n",file_name);
exit(0); exit(0);
} }
printf ("str:%s len:%d i0:%d i1:%d\n", str, strlen(str),i0,i1); printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2);
/**Added by dhanya*/ /**Added by dhanya*/
if(i1 == 0){ if(i1 == 0){
Feb_Control_AddModule1(0,0xff,0,1);//global send /*Feb_Control_AddModule1(0,0xff,0,1);//global send
Feb_Control_PrintModuleList(); Feb_Control_PrintModuleList();*/
if(!Feb_Control_AddModule1(i0,i1,0,1)){
if(!Feb_Control_AddModule1(i0,i2,0,1)){
printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
exit(0); exit(0);
} }
}else{ }else{
Feb_Control_AddModule1(0,0,0xff,1);//global send
Feb_Control_PrintModuleList(); /* Feb_Control_AddModule1(0,0,0xff,1);//global send
if(!Feb_Control_AddModule1(i0,0,i1,1)){ Feb_Control_PrintModuleList();*/
if(!Feb_Control_AddModule1(i0,0,i2,1)){
printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
exit(0); exit(0);
} }
} }
//memaddress++;
Feb_Control_PrintModuleList();
/* if(!Feb_Control_AddModule1(i0,i1)){ /* if(!Feb_Control_AddModule1(i0,i1)){
printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
@ -345,7 +437,6 @@ int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address){
int Feb_Control_AddModule1(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module){ //bot_address 0 for half module int Feb_Control_AddModule1(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module){ //bot_address 0 for half module
int parameters_ok = 1; int parameters_ok = 1;
unsigned int pre_module_index = 0; unsigned int pre_module_index = 0;
if(Feb_Control_GetModuleIndex(module_number,&pre_module_index)){ if(Feb_Control_GetModuleIndex(module_number,&pre_module_index)){
printf("\tRemoving previous assignment of module number %d.\n",module_number); printf("\tRemoving previous assignment of module number %d.\n",module_number);
// free(modules[pre_module_index]); // free(modules[pre_module_index]);
@ -391,7 +482,7 @@ int Feb_Control_AddModule1(unsigned int module_number, unsigned int top_address,
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
printf("Reading Setup file for module number:%d\n",module_num);
char line[100]; char line[100];
char str[100]; char str[100];
int i0; int i0;
@ -465,23 +556,26 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
} }
if(module_num>0) if(module_num>0)
sprintf(str,"mod%d::%s",module_num,str); sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/
if(!Feb_Control_SetDAC(str,f0,1)) if(!Feb_Control_SetDAC(str,f0,1))
printf("error in string: %s",str); printf("error in string: %s",str);
} }
} }
fclose(fp); fclose(fp);
printf("Done reading set up file\n");
return 1; return 1;
} }
int Feb_Control_CheckSetup(){ int Feb_Control_CheckSetup(){
printf("Checking Set up\n");
unsigned int i,j; unsigned int i,j;
int ok = 1; int ok = 1;
for(i=0;i<moduleSize;i++){ /*for(i=0;i<moduleSize;i++){*/
i = Feb_Control_current_index;
for(j=0;j<4;j++){ for(j=0;j<4;j++){
if(Module_GetTopIDelay(&modules[i],j)<0){ if(Module_GetTopIDelay(&modules[i],j)<0){
printf("Warning: module %d's idelay top number %d not set.\n",Module_GetModuleNumber(&modules[i]),j); printf("Warning: module %d's idelay top number %d not set.\n",Module_GetModuleNumber(&modules[i]),j);
@ -506,8 +600,8 @@ int Feb_Control_CheckSetup(){
ok=0; ok=0;
} }
} }
} /* }*/
printf("Done Checking Set up\n");
return ok; return ok;
} }
@ -646,16 +740,20 @@ float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vm
int Feb_Control_SetHighVoltage(float value){ int Feb_Control_SetHighVoltage(float value){
return Feb_Control_SetHighVoltage1(0,value); return Feb_Control_SetHighVoltage1(Feb_Control_current_mod,value);
} }
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){ int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
unsigned int module_index=0; unsigned int module_index=0;
unsigned int i; unsigned int i;
if(!Feb_Control_GetModuleIndex(module_num,&module_index)||!Module_TopAddressIsValid(&modules[module_index])){
printf("Error could not set high voltage module number %d invalid.\n",module_num); if(Module_TopAddressIsValid(&modules[module_index])){
return 0; if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/
} printf("Error could not set high voltage module number %d invalid.\n",module_num);
return 0;
}
}else
return 0;
if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0; if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0;
@ -696,8 +794,9 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){ int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){
char* local_s = dac_str; char* local_s = dac_str;
char temp[50]; char temp[50];
*module_index = 1; *module_index = Feb_Control_current_index;
/*
char* p1 = strstr(local_s,"mod");//size_t p1 = local_s.find("mod"); char* p1 = strstr(local_s,"mod");//size_t p1 = local_s.find("mod");
char* p2 = strstr(local_s,"::");//size_t p2 =local_s.find("::"); char* p2 = strstr(local_s,"::");//size_t p2 =local_s.find("::");
if(p1!=NULL&&p2!=NULL&&(p1+3)<p2){//if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){ if(p1!=NULL&&p2!=NULL&&(p1+3)<p2){//if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){
@ -711,7 +810,7 @@ int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int*
} }
strcpy(local_s,p2+2);//local_s = local_s.substr(p2+2); strcpy(local_s,p2+2);//local_s = local_s.substr(p2+2);
} }
*/
*top = 1;//make them both 1 instead of this *top = 1;//make them both 1 instead of this
*bottom = 1; *bottom = 1;
@ -960,8 +1059,8 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
} //end row loop } //end row loop
if(Module_TopAddressIsValid(&modules[0])){ if(Module_TopAddressIsValid(&modules[0])){
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[1]),0,0,1024,trimbits_to_load_r)|| if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[1]),0,0,1024,trimbits_to_load_l)|| !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
@ -969,8 +1068,8 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
return 0; return 0;
} }
}else{ }else{
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[1]),0,0,1024,trimbits_to_load_r)|| if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[1]),0,0,1024,trimbits_to_load_l)|| !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
@ -995,15 +1094,22 @@ unsigned int* Feb_Control_GetTrimbits(){
unsigned int Feb_Control_AddressToAll(){ unsigned int Feb_Control_AddressToAll(){printf("in Feb_Control_AddressToAll()\n");
if(moduleSize==0) return 0; if(moduleSize==0) return 0;
if(Module_BottomAddressIsValid(&modules[0])){ if(Module_BottomAddressIsValid(&modules[1])){
//printf("************* bottom\n"); printf("************* bottom\n");
return Module_GetBottomLeftAddress(&modules[0])|Module_GetBottomRightAddress(&modules[0]); //if(Feb_Control_am_i_master)
return Module_GetBottomLeftAddress(&modules[1])|Module_GetBottomRightAddress(&modules[1]);
// else return 0;
} }
//printf("************* top\n"); printf("************* top\n");
return Module_GetTopLeftAddress(&modules[0])|Module_GetTopRightAddress(&modules[0]); // if(Feb_Control_am_i_master)
return Module_GetTopLeftAddress(&modules[0])|Module_GetTopRightAddress(&modules[0]);
// else return 0;
} }
@ -1048,17 +1154,19 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
int Feb_Control_AcquisitionInProgress(){ int Feb_Control_AcquisitionInProgress(){
unsigned int status_reg_r=0,status_reg_l=0; unsigned int status_reg_r=0,status_reg_l=0;
if(Module_BottomAddressIsValid(&modules[1])){
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[1]),&status_reg_r))) int ind = Feb_Control_current_index;
if(Module_BottomAddressIsValid(&modules[ind])){
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r)))
{printf("ERROR: Trouble reading Status register. bottom right address\n");return 0;} {printf("ERROR: Trouble reading Status register. bottom right address\n");return 0;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[1]),&status_reg_l))) if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. bottom left address\n");return 0;} {printf("ERROR: Trouble reading Status register. bottom left address\n");return 0;}
}else{ }else{
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[1]),&status_reg_r))) if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r)))
{printf("ERROR: Trouble reading Status register. top right address\n");return 0;} {printf("ERROR: Trouble reading Status register. top right address\n");return 0;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[1]),&status_reg_l))) if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. top left address\n");return 0;} {printf("ERROR: Trouble reading Status register. top left address\n");return 0;}
} }
if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/return 1;} if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/return 1;}
@ -1244,8 +1352,8 @@ int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity){
} }
int Feb_Control_SetNExposures(unsigned int n_images){ int Feb_Control_SetNExposures(unsigned int n_images){
if(!Feb_Control_nimages){ if(!n_images){
printf("Warning nimages must be greater than zero.%d\n",Feb_Control_nimages); printf("Warning nimages must be greater than zero.%d\n",n_images);
return 0; return 0;
} }
@ -1399,7 +1507,7 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition*********
return 0; return 0;
} }
if(!Feb_Control_SetStaticBits(Feb_Control_staticBits&(DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8))){ if(!Feb_Control_SetStaticBits1(Feb_Control_staticBits&(DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8))){
printf("Trouble setting static bits ...\n");; printf("Trouble setting static bits ...\n");;
return 0; return 0;
} }
@ -1414,6 +1522,7 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition*********
return 0; return 0;
} }
reg_nums[0]=DAQ_REG_CTRL; reg_nums[0]=DAQ_REG_CTRL;
reg_vals[0]=0; reg_vals[0]=0;
reg_nums[1]=DAQ_REG_NEXPOSURES; reg_nums[1]=DAQ_REG_NEXPOSURES;
@ -1422,6 +1531,53 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition*********
reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec); reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec);
reg_nums[3]=DAQ_REG_EXPOSURE_REPEAT_TIMER; reg_nums[3]=DAQ_REG_EXPOSURE_REPEAT_TIMER;
reg_vals[3]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec); reg_vals[3]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec);
///*
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),4,reg_nums,reg_vals,0,0)){
printf("Trouble starting acquisition....\n");;
return 0;
}
unsigned int masterHalfModuleMode = 0;
reg_nums[0]=DAQ_REG_CHIP_CMDS;
reg_vals[0]=(masterHalfModuleMode|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),1,reg_nums,reg_vals,0,0)){
printf("Trouble writing commands....\n");;
return 0;
}
/*
masterHalfModuleMode = 0x80000000;
reg_nums[0]=DAQ_REG_CHIP_CMDS;
reg_vals[0]=(masterHalfModuleMode|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),1,reg_nums,reg_vals,0,0)){
printf("Trouble writing commands....\n");;
return 0;
}
*/
//if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),1,reg_nums,reg_vals,0,0)){
///*
int i;
for(i=0;i<14;i++){
reg_nums[i]=DAQ_REG_CTRL;
reg_vals[i]=0;
}
reg_nums[14]=DAQ_REG_CTRL;
reg_vals[14]=ACQ_CTRL_START;
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){
printf("Trouble starting acquisition....\n");;
return 0;
}
//*/
/*
reg_nums[4]=DAQ_REG_CHIP_CMDS; reg_nums[4]=DAQ_REG_CHIP_CMDS;
reg_vals[4]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode); reg_vals[4]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
int i; int i;
@ -1432,11 +1588,12 @@ int Feb_Control_StartAcquisition(){printf("****** starting acquisition*********
reg_nums[19]=DAQ_REG_CTRL; reg_nums[19]=DAQ_REG_CTRL;
reg_vals[19]=ACQ_CTRL_START; reg_vals[19]=ACQ_CTRL_START;
// if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),20,reg_nums,reg_vals,0,0)){ if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),20,reg_nums,reg_vals,0,0)){
printf("Trouble starting acquisition....\n");; printf("Trouble starting acquisition....\n");;
return 0; return 0;
} }
*/
return 1; return 1;
} }

View File

@ -66,7 +66,8 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
int Feb_Control_IsBottomModule(); int Feb_Control_IsBottomModule();
int Feb_Control_GetModuleNumber();
void Feb_Control_Set_Master();
void Feb_Control_ClearModules(); void Feb_Control_ClearModules();
@ -102,7 +103,7 @@ int Feb_Control_IsBottomModule();
int Feb_Control_ResetChipCompletely(); int Feb_Control_ResetChipCompletely();
struct sockaddr_in Feb_Control_serv_addr; //struct sockaddr_in Feb_Control_serv_addr;
/* /*
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port); int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int Feb_Control_WriteNRead(char* message, int length, int max_length); int Feb_Control_WriteNRead(char* message, int length, int max_length);

View File

@ -105,6 +105,7 @@ int initDetector(){
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
Feb_Control_Init();
printf("FEb control constructor done\n"); printf("FEb control constructor done\n");
Beb_Beb(-1); Beb_Beb(-1);
printf("BEB constructor done\n"); printf("BEB constructor done\n");
@ -126,16 +127,32 @@ int initDetector(){
setThresholdEnergy(8000,0); setThresholdEnergy(8000,0);
setReadOutFlags(PARALLEL); setReadOutFlags(PARALLEL);
setSpeed(0,1);//clk_devider,half speed setSpeed(0,1);//clk_devider,half speed
setHighVolage(150,0); setHighVolage(150,0);
setIODelay(675,0); setIODelay(675,0);
setTiming(AUTO_TIMING); setTiming(AUTO_TIMING);
//setMaster(GET_MASTER); //setMaster(GET_MASTER);
int enable[2] = {0,1}; int enable[2] = {0,1};
setExternalGating(enable);//disable external gating setExternalGating(enable);//disable external gating
if(!Feb_Control_IsBottomModule()) Feb_Control_SetTestModeVariable(0);
trialMasterMode = IS_MASTER;
Feb_Control_CheckSetup();
//if(!Feb_Control_IsBottomModule()){
//if(getDetectorNumber()==0xbeb031){
printf("************** master ********************\n");
trialMasterMode = IS_MASTER;
Feb_Control_Set_Master();
//}
//else printf("************** slave ********************\n");
if(Feb_Control_IsBottomModule())
printf("BOTTOM ***************\n");
else
printf("TOP ***************\n");
return 1; return 1;
} }
@ -325,7 +342,7 @@ int getADC(enum detDacIndex ind, int imod){
int setIODelay(int val, int imod){ int setIODelay(int val, int imod){
if(val!=-1){ if(val!=-1){
printf(" Setting IO Delay: %d\n",val); printf(" Setting IO Delay: %d\n",val);
if(Feb_Control_SetIDelays(0,val)) if(Feb_Control_SetIDelays(Feb_Control_GetModuleNumber(),val))
eiger_iodelay = val; eiger_iodelay = val;
} }
return eiger_iodelay; return eiger_iodelay;
@ -382,7 +399,7 @@ int setModule(sls_detector_module myMod){
} }
Feb_Control_SetTrimbits(0,tt); Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt);
return 0; return 0;
@ -456,18 +473,23 @@ enum detectorSettings setSettings(enum detectorSettings sett, int imod){
int startStateMachine(){ int startStateMachine(){
int ret;
if(trialMasterMode == IS_MASTER){ if(trialMasterMode == IS_MASTER){
printf("Going to start acquisition\n"); printf("Going to start acquisition\n");
Feb_Control_StartAcquisition(); Feb_Control_StartAcquisition();
} }
//if(trialMasterMode == IS_MASTER){
printf("requesting images\n"); printf("requesting images\n");
int ret = startReadOut(); ret = startReadOut();
//}
while(getRunStatus() == IDLE); if(trialMasterMode == IS_MASTER){
printf("Acquiring..\n"); /*for(i=0;i<3;i++)
usleep(1000000);*/
while(getRunStatus() == IDLE);
printf("Acquiring..\n");
}
printf("Returning\n");
return ret; return ret;
} }
@ -490,8 +512,10 @@ int startReadOut(){
dst_requested[0] = 1; dst_requested[0] = 1;
while(dst_requested[on_dst]){ while(dst_requested[on_dst]){
//waits on data //waits on data
if((ret_val = (!Beb_RequestNImages(0,1,send_to_ten_gig,on_dst,nimages_per_request,0)|| int beb_num = 24;//Feb_Control_GetModuleNumber();
!Beb_RequestNImages(0,2,send_to_ten_gig,0x20|on_dst,nimages_per_request,0))))
if((ret_val = (!Beb_RequestNImages(beb_num,1,send_to_ten_gig,on_dst,nimages_per_request,0)||
!Beb_RequestNImages(beb_num,2,send_to_ten_gig,0x20|on_dst,nimages_per_request,0))))
break; break;
dst_requested[on_dst++]=0; dst_requested[on_dst++]=0;
on_dst%=ndsts_in_use; on_dst%=ndsts_in_use;
@ -505,6 +529,7 @@ int startReadOut(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
if(trialMasterMode == IS_MASTER){
int i = Feb_Control_AcquisitionInProgress(); int i = Feb_Control_AcquisitionInProgress();
if(i== 0){ if(i== 0){
//printf("IDLE\n"); //printf("IDLE\n");
@ -513,6 +538,9 @@ enum runStatus getRunStatus(){
//printf("RUNNING\n"); //printf("RUNNING\n");
return RUNNING; return RUNNING;
} }
}
return IDLE;
} }
@ -698,7 +726,7 @@ int configureMAC(int ipad, long long int macad, long long int detectormacadd, in
printf("dst_mac:%s\n",dst_mac); printf("dst_mac:%s\n",dst_mac);
int beb_num = 34; int beb_num = 24;//Feb_Control_GetModuleNumber();
int header_number = 0; int header_number = 0;
int dst_port = udpport; int dst_port = udpport;

View File

@ -1528,7 +1528,7 @@ slsDetectorDefs::runStatus multiSlsDetector::getRunStatus() {
return s; return s;
} }
for (int i=1; i<thisMultiDetector->numberOfDetectors; i++) { for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
s1=detectors[i]->getRunStatus(); s1=detectors[i]->getRunStatus();
if(detectors[i]->getErrorMask()) if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i)); setErrorMask(getErrorMask()|(1<<i));

View File

@ -54,7 +54,7 @@ int init_detector(int b) {
#endif #endif
}else{ }else{
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
//Feb_Control_FebControl(); Feb_Control_Init();
// printf("FEb control constructor done\n"); // printf("FEb control constructor done\n");
/* Beb_Beb(-1); /* Beb_Beb(-1);
printf("BEB constructor done\n");*/ printf("BEB constructor done\n");*/