added the code for toggle bit to know when acquisition started in febcontrol and list, indentation as well

This commit is contained in:
Dhanya Maliakal
2015-05-20 12:01:49 +02:00
parent 1f1581a1fa
commit 302d9ca0ed
6 changed files with 809 additions and 797 deletions

View File

@ -101,7 +101,7 @@
#define DAQ_STATUS_TOKEN_OUT 0x20 #define DAQ_STATUS_TOKEN_OUT 0x20
#define DAQ_STATUS_SERIAL_OUT 0x40 #define DAQ_STATUS_SERIAL_OUT 0x40
#define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80 #define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80
#define DAQ_STATUS_DAQ_RUN_TOGGLE 0x200
//data delay registers //data delay registers
#define CHIP_DATA_OUT_DELAY_REG_CTRL 1 #define CHIP_DATA_OUT_DELAY_REG_CTRL 1

View File

@ -1095,7 +1095,7 @@ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret
return 0; return 0;
} }
*ret_status = (0x00FF0000 & *ret_status) >> 16; *ret_status = (0x02FF0000 & *ret_status) >> 16;
return 1; return 1;
} }
@ -1109,6 +1109,61 @@ int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){
return Feb_Control_WaitForFinishedFlag(sleep_time_us); return Feb_Control_WaitForFinishedFlag(sleep_time_us);
} }
int Feb_Control_AcquisitionInProgress(){
unsigned int status_reg_r=0,status_reg_l=0;
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;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. bottom left address\n");return 0;}
}else{
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r)))
{printf("ERROR: Trouble reading Status register. top right address\n");return 0;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. top left address\n");return 0;}
}
//running
if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/
return 1;
}
//idle
return 0;
}
int Feb_Control_AcquisitionStartedBit(){
unsigned int status_reg_r=0,status_reg_l=0;
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 -1;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. bottom left address\n");return -1;}
}else{
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r)))
{printf("ERROR: Trouble reading Status register. top right address\n"); return -1;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. top left address\n");return -1;}
}
//doesnt mean it started, just the bit
if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUN_TOGGLE)
return 1;
return 0;
}
int Feb_Control_WaitForFinishedFlag(int sleep_time_us){ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
int is_running = Feb_Control_AcquisitionInProgress(); int is_running = Feb_Control_AcquisitionInProgress();
while(is_running){ while(is_running){
@ -1123,43 +1178,22 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
return 1; return 1;
} }
int Feb_Control_AcquisitionInProgress(){
unsigned int status_reg_r=0,status_reg_l=0;
int ind = Feb_Control_current_index; int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
if(Module_BottomAddressIsValid(&modules[ind])){ int value = prev_flag;
while(value == prev_flag){
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r))) usleep(sleep_time_us);
{printf("ERROR: Trouble reading Status register. bottom right address\n");return 0;} value = Feb_Control_AcquisitionStartedBit();
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l)))
{printf("ERROR: Trouble reading Status register. bottom left address\n");return 0;}
}else{
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r)))
{printf("ERROR: Trouble reading Status register. top right address\n");
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[0]),&status_reg_r)))
printf("ERROR: error with normal register\n");
else
printf("**********NO error reading normal register\n");
return 0;}
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l)))
{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;}
/* //did not start
if(!(GetDAQStatusRegister(modules[i]->Module_GetTopLeftAddress(),status_reg_r)&&GetDAQStatusRegister(modules[i]->Module_GetTopRightAddress(),status_reg_l))){ if(value == -1)
for(int i=0;i<2;i++) printf("Waring trouble reading status register. Returning zero to avoid inifite loops, this could cause trouble!"\n");; return 0;
return 0; //to avoid inifite loops
}
if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) return 1;
}
*/
/*printf("**idle\n");*/ return 1;
return 0; //i.e. not running (status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING;
} }
int Feb_Control_Reset(){ int Feb_Control_Reset(){
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)){ 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)){
printf("Warning: Could not reset daq, no response.\n"); printf("Warning: Could not reset daq, no response.\n");

View File

@ -149,8 +149,10 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_StartAcquisition(); int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition(); int Feb_Control_StopAcquisition();
int Feb_Control_AcquisitionInProgress(); int Feb_Control_AcquisitionInProgress();
int Feb_Control_AcquisitionStartedBit();
/*int Feb_Control_WaitForFinishedFlag(int sleep_time_us=5000);*/ /*int Feb_Control_WaitForFinishedFlag(int sleep_time_us=5000);*/
int Feb_Control_WaitForFinishedFlag(int sleep_time_us); int Feb_Control_WaitForFinishedFlag(int sleep_time_us);
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag);
//functions for setting up exposure //functions for setting up exposure
void Feb_Control_PrintAcquisitionSetup(); void Feb_Control_PrintAcquisitionSetup();

View File

@ -101,7 +101,7 @@
#define DAQ_STATUS_TOKEN_OUT 0x20 #define DAQ_STATUS_TOKEN_OUT 0x20
#define DAQ_STATUS_SERIAL_OUT 0x40 #define DAQ_STATUS_SERIAL_OUT 0x40
#define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80 #define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80
#define DAQ_STATUS_DAQ_RUN_TOGGLE 0x200
//data delay registers //data delay registers
#define CHIP_DATA_OUT_DELAY_REG_CTRL 1 #define CHIP_DATA_OUT_DELAY_REG_CTRL 1

View File

@ -502,58 +502,34 @@ int startReceiver(int d){
int startStateMachine(){ int startStateMachine(){
int ret; int ret,prev_flag;
//if(master){ //get the DAQ toggle bit
prev_flag = Feb_Control_AcquisitionStartedBit();
printf("Going to start acquisition\n"); printf("Going to start acquisition\n");
Feb_Control_StartAcquisition(); Feb_Control_StartAcquisition();
//}
//do not read status here, cannot get images then
////if(trialMasterMode == IS_MASTER){
printf("requesting images\n"); printf("requesting images\n");
ret = startReadOut(); ret = startReadOut();
////}
//if(trialMasterMode == IS_MASTER){
//wait for acquisition start
//if(master){ if(ret == OK){
/* if(!Feb_Control_WaitForStartedFlag(5000, prev_flag)){
* int i=0; cprintf(RED,"Error: Acquisition did no start or trouble reading register\n");
if(getRunStatus() == IDLE){ ret = FAIL;
for(i=0;i<100000;i++){
usleep(1000);
if(getRunStatus() != IDLE){
printf("*****i=%d\n",i);
break;
} }
cprintf(GREEN,"***Acquisition started\n");
} }
//while(getRunStatus() == IDLE); /*while(getRunStatus() == IDLE){printf("waiting for being not idle anymore\n");}*/
//}
printf("*****Acquiring...\n");
}
*/
while(getRunStatus() == IDLE){
printf("waiting for being not idle anymore\n");
}
printf("*****Acquiring...\n");
//}
/*else usleep(1000000);
printf("****Returning\n");*/
return ret; return ret;
} }
int stopStateMachine(){ int stopStateMachine(){
//if(trialMasterMode == IS_MASTER){
printf("Going to stop acquisition\n"); printf("Going to stop acquisition\n");
if(Feb_Control_StopAcquisition()) if(Feb_Control_StopAcquisition())
return OK; return OK;
//}else return OK;
return FAIL; return FAIL;
} }
@ -600,8 +576,8 @@ enum runStatus getRunStatus(){
char *readFrame(int *ret, char *mess){ char *readFrame(int *ret, char *mess){
//if(master){ //if(master){
if(!Feb_Control_WaitForFinishedFlag(5000)) if(!Feb_Control_WaitForFinishedFlag(5000))
printf("error in waiting for finished flag\n"); cprintf(RED,"Error: Waiting for finished flag\n");
printf("Acquisition finished\n"); cprintf(GREEN,"Acquisition finished***\n");
//usleep(0); //usleep(0);
usleep(1000000); usleep(1000000);
printf("*****Done Waiting...\n"); printf("*****Done Waiting...\n");