|
|
|
@ -18,6 +18,7 @@
|
|
|
|
|
#include "FebRegisterDefs.h"
|
|
|
|
|
#include "FebControl.h"
|
|
|
|
|
#include "Beb.h"
|
|
|
|
|
#include "slsDetectorServer_defs.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -906,7 +907,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!Feb_Control_Reset()) cprintf(RED,"Warning could not reset DAQ.\n");
|
|
|
|
|
if(Feb_Control_Reset() == STATUS_ERROR) cprintf(RED,"Warning could not reset DAQ.\n");
|
|
|
|
|
int l_r; //printf("222\n");
|
|
|
|
|
for(l_r=0;l_r<2;l_r++){ // l_r loop
|
|
|
|
|
//printf("\nl_r:%d\t\t",l_r);
|
|
|
|
@ -914,7 +915,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
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))){
|
|
|
|
|
&&(Feb_Control_StartDAQOnlyNWaitForFinish(5000) == STATUS_IDLE))){
|
|
|
|
|
printf("Could not select chips\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -980,7 +981,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
|
|
|
|
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,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_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
printf(" some errror!\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -991,7 +992,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
|
|
|
|
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,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_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
printf(" some errror!\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1073,29 +1074,29 @@ int Feb_Control_AcquisitionInProgress(){
|
|
|
|
|
|
|
|
|
|
//deactivated should return end of acquisition
|
|
|
|
|
if(!Feb_Control_activated)
|
|
|
|
|
return 0;
|
|
|
|
|
return STATUS_IDLE;
|
|
|
|
|
|
|
|
|
|
int ind = Feb_Control_current_index;
|
|
|
|
|
if(Module_BottomAddressIsValid(&modules[ind])){
|
|
|
|
|
|
|
|
|
|
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r)))
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return 0;}
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return STATUS_ERROR;}
|
|
|
|
|
if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l)))
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return 0;}
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return STATUS_ERROR;}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r)))
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. top right address\n");return 0;}
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. top right address\n");return STATUS_ERROR;}
|
|
|
|
|
if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l)))
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. top left address\n");return 0;}
|
|
|
|
|
{cprintf(RED,"Error: Trouble reading Status register. top left address\n");return STATUS_ERROR;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//running
|
|
|
|
|
if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/
|
|
|
|
|
return 1;
|
|
|
|
|
return STATUS_RUNNING;
|
|
|
|
|
}
|
|
|
|
|
//idle
|
|
|
|
|
return 0;
|
|
|
|
|
return STATUS_IDLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1132,16 +1133,25 @@ int Feb_Control_AcquisitionStartedBit(){
|
|
|
|
|
|
|
|
|
|
int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
|
|
|
|
|
int is_running = Feb_Control_AcquisitionInProgress();
|
|
|
|
|
while(is_running){
|
|
|
|
|
|
|
|
|
|
int check_error = 0;
|
|
|
|
|
|
|
|
|
|
// it will break out if it is idle or if check_error is more than 5 times
|
|
|
|
|
while(is_running != STATUS_IDLE){
|
|
|
|
|
usleep(sleep_time_us);
|
|
|
|
|
is_running = Feb_Control_AcquisitionInProgress();
|
|
|
|
|
}
|
|
|
|
|
if(is_running!=0){
|
|
|
|
|
printf("\n\nWarning WaitForFinishedFlag comunication problem..\n\n");
|
|
|
|
|
return 0; //communication problem
|
|
|
|
|
|
|
|
|
|
// check error only 5 times (ensuring it is not something that happens sometimes)
|
|
|
|
|
if (is_running == STATUS_ERROR) {
|
|
|
|
|
if (check_error == 5)
|
|
|
|
|
break;
|
|
|
|
|
check_error++;
|
|
|
|
|
}// reset check_error for next time
|
|
|
|
|
else check_error = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
return is_running;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1151,6 +1161,10 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
|
|
|
|
if(!Feb_Control_activated)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
//did not start
|
|
|
|
|
if(prev_flag == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
int value = prev_flag;
|
|
|
|
|
while(value == prev_flag){
|
|
|
|
|
usleep(sleep_time_us);
|
|
|
|
@ -1183,7 +1197,9 @@ int Feb_Control_Reset(){
|
|
|
|
|
int Feb_Control_SetStaticBits(){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
//program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
|
|
|
|
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) ||
|
|
|
|
|
!Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) ||
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: Could not set static bits\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1390,7 +1406,7 @@ unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Feb_Control_ResetChipCompletely(){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not ResetChipCompletely() with 0x%x.\n",DAQ_RESET_COMPLETELY);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1401,13 +1417,13 @@ int Feb_Control_ResetChipCompletely(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Feb_Control_ResetChipPartially(){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not ResetChipPartially with periphery\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
printf("Chip reset periphery 0x%x\n",DAQ_RESET_PERIPHERY);
|
|
|
|
|
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COLUMN_SELECT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COLUMN_SELECT) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not ResetChipPartially with column select\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1456,7 +1472,7 @@ int Feb_Control_PrepareForAcquisition(){//return 1;
|
|
|
|
|
Feb_Control_PrintAcquisitionSetup();
|
|
|
|
|
|
|
|
|
|
// if(!Reset()||!ResetDataStream()){
|
|
|
|
|
if(!Feb_Control_Reset()){
|
|
|
|
|
if(Feb_Control_Reset() == STATUS_ERROR){
|
|
|
|
|
printf("Trouble reseting daq or data stream...\n");;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1580,7 +1596,10 @@ int Feb_Control_Pulse_Pixel(int npulses, int x, int y){
|
|
|
|
|
Feb_Control_SetInTestModeVariable(1); //on
|
|
|
|
|
Feb_Control_SetStaticBits();
|
|
|
|
|
Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY|DAQ_RESET_COLUMN_SELECT);
|
|
|
|
|
Feb_Control_StartDAQOnlyNWaitForFinish(5000);
|
|
|
|
|
if (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE) {
|
|
|
|
|
cprintf(RED,"Warning: could not pulse pixel as status not idle\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int serial_in = 8<<(4*(7-x%8));
|
|
|
|
|
if(!Feb_Control_Shift32InSerialIn(serial_in)){
|
|
|
|
@ -1610,7 +1629,7 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) ||
|
|
|
|
|
!Feb_Control_SetCommandRegister(c) ||
|
|
|
|
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not PulsePixelNMove(...).\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1624,7 +1643,7 @@ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) ||
|
|
|
|
|
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) ||
|
|
|
|
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not shift in 32.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1634,7 +1653,7 @@ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){
|
|
|
|
|
|
|
|
|
|
int Feb_Control_SendTokenIn(){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_SEND_A_TOKEN_IN) ||
|
|
|
|
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not SendTokenIn().\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1650,7 +1669,7 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) ||
|
|
|
|
|
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) ||
|
|
|
|
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(RED,"Warning: could not clock row clock.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1680,7 +1699,7 @@ int Feb_Control_PulseChip(int npulses){
|
|
|
|
|
for(i=0;i<npulses;i++){
|
|
|
|
|
if(!Feb_Control_SetCommandRegister(DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED|DAQ_RESET_PERIPHERY|DAQ_RESET_COLUMN_SELECT))
|
|
|
|
|
cprintf(RED,"some set command register error\n");
|
|
|
|
|
if(!Feb_Control_StartDAQOnlyNWaitForFinish(5000))
|
|
|
|
|
if((Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE))
|
|
|
|
|
cprintf(RED,"some wait error\n");
|
|
|
|
|
}
|
|
|
|
|
Feb_Control_SetExternalEnableMode(on,1);
|
|
|
|
@ -1849,7 +1868,7 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
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)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -1858,7 +1877,7 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
|
|
|
|
if(Feb_Control_activated){
|
|
|
|
|
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)){
|
|
|
|
|
(Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){
|
|
|
|
|
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|