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

This commit is contained in:
bergamaschi 2015-06-12 13:00:21 +02:00
commit 2b05ceb281
17 changed files with 1042 additions and 853 deletions

View File

@ -494,6 +494,9 @@ void Beb_AdjustIPChecksum(struct udp_header_type *ip){
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty){
// This is a dead function, will be removed in future
// ==================================================
unsigned int i = 1;/*Beb_GetBebInfoIndex(beb_number); //zero is the global send*/
Beb_send_ndata = 3;
@ -510,9 +513,15 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i
Beb_send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets;
#ifdef MARTIN
cprintf(GREEN, "Beb_send_data[1]:%X\n",Beb_send_data[1]);
#endif
Beb_send_data[2] = 0;
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
#ifdef MARTIN
cprintf(GREEN, "Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]);
#endif
if(!Beb_WriteTo(i)) return 0;
@ -530,47 +539,155 @@ int Beb_SetUpTransferParameters(short the_bit_mode){
return 1;
}
int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){
int Beb_StopAcquisition()
{
volatile u_int32_t* ptrl;
volatile u_int32_t* ptrr;
// Mapping
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1)
{
printf("\nCan't find /dev/mem!\n");
return 0;
}
u_int32_t CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0xC5000000 );
if (CSP0BASE == (u_int32_t)MAP_FAILED)
{
printf("\nCan't map memmory area!!\n");
return 0;
}
ptrl = (u_int32_t*)(CSP0BASE);
ptrr = (u_int32_t*)(CSP0BASE+0x100);
*(ptrl+7) = (1 << 30);
*(ptrr+7) = (1 << 30);
*(ptrl+7) = 0;
*(ptrr+7) = 0;
close(fd);
}
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){
if(dst_number>64) return 0;
unsigned int header_size = 4; //4*64 bits
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
unsigned int npackets = ten_gig ? Beb_bit_mode*4 : Beb_bit_mode*16;
int in_two_requests = (!ten_gig&&Beb_bit_mode==32);
volatile u_int32_t* ptrl;
volatile u_int32_t* ptrr;
u_int32_t send_header_command;
u_int32_t send_frame_command;
if(in_two_requests) npackets/=2;
// printf("npackets:%d\n",npackets);
//usleep needed after acquisition start, else you miss the single images
usleep(10000);//less than this and it starts sending half stuff sometimes
//printf("beb no:%d left_right:%d ten_gig:%d dst_number:%d #images:%d header_size:%d test_just_send_out_packets_no_wait:%d\n",beb_number,left_right,ten_gig,dst_number,nimages, header_size,test_just_send_out_packets_no_wait);
//printf("here: "<<beb_number<<","<<left_right<<","<<ten_gig<<","<<dst_number<<","<<1<<","<<header_size<<","<<test_just_send_out_packets_no_wait\n");
/*
unsigned int i;
for(i=0;i<nimages;i++){
//header then data request
// usleep(10000);
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,1,header_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
// usleep(10000);
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
usleep(1000);
if(in_two_requests){if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait)){printf("Send failed\n");return 0;}
}
#ifdef MARTIN
cprintf(RED, "----Beb_RequestNImages Start----\n");
cprintf(RED, "beb_number:%X, ten_gig:%X,dst_number:%X,npackets:%X,Beb_bit_mode:%X,header_size:%X,nimages:%d,test_just_send_out_packets_no_wait:%X\n",beb_number,ten_gig,dst_number,npackets,Beb_bit_mode,header_size,nimages,test_just_send_out_packets_no_wait);
#endif
// CMD_GEN core registers
//
// base for left feb fpga + 0x000
// base for right feb fpga + 0x100 Bytes
//
// OFFSETs given in Bytes
// base+00 0xC0DE0001 (static r/o)
// base+04 0x636D6467 (static r/o, ASCII for "CMDG")
//
// base+08 1st 32bits of 1st command
// base+0c 2nd 32bits of 1st command
//
// base+10 1st 32bits of 2nd command
// base+14 2nd 32bits of 2nd command
//
// base+1c command counter (sends n commands)
// <32 Bit mode : 2 commands for 1 frame neccessary (header + frame) (10 frames = 20 commands)
// 32 Bit mode : 3 commands for 1 frame neccessary (header + 1st halfframe + 2nd halfframe) (10 frames = 30 commands)
// if > 0 core starts operation
//
// base+20 command mode (for 32 bit mode)
// 0 for 2 command mode (send 1st command and 2nd command) (header + frame)
// 1 on bit 31 for 3 command mode (send 1st command, 2nd command, and 2nd command) (header + 1st halfframe + 2nd halfframe)
//
//
// Warning: Hard coded base address 0xc5000000 (TBD)
//
// Mapping
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1)
{
printf("\nCan't find /dev/mem!\n");
return 0;
}
*/
unsigned int i;
for(i=0;i<nimages;i++){
//header then data request
if(!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,1,header_size,test_just_send_out_packets_no_wait) ||
!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait) ||
(in_two_requests&&!Beb_SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait))){
printf("SendMultiReadRequest failed\n");
return 0;
}
u_int32_t CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0xC5000000 );
if (CSP0BASE == (u_int32_t)MAP_FAILED)
{
printf("\nCan't map memmory area!!\n");
return 0;
}
ptrl = (u_int32_t*)(CSP0BASE);
ptrr = (u_int32_t*)(CSP0BASE+0x100);
int i;
#ifdef MARTIN
for (i=0; i < 10; i++)
printf("%X\n",*(ptrl+i));
#endif
// Generating commands
send_header_command = 0x62000000 | (!test_just_send_out_packets_no_wait) << 27 | (ten_gig==1) << 24 | header_size << 14 | 0;
send_frame_command = 0x62000000 | (!test_just_send_out_packets_no_wait) << 27 | (ten_gig==1) << 24 | packet_size << 14 | (npackets-1);
#ifdef MARTIN
for (i=0; i < 10; i++)
printf("%X\n",*(ptrl+i));
printf("%d\n",in_two_requests);
#endif
// Wait until last command was send successfully
// while (*(ptrl+6) != 0);
// while (*(ptrr+6) != 0);
//"0x20 << 8" is dst_number (0x00 for left, 0x20 for right)
//Left
*(ptrl+2) = 0;
*(ptrl+3) = send_header_command;
*(ptrl+4) = 0;
*(ptrl+5) = send_frame_command;
*(ptrl+7) = in_two_requests << 31;
// Right
*(ptrr+2) = 0;
*(ptrr+3) = send_header_command | 0x2000;
*(ptrr+4) = 0;
*(ptrr+5) = send_frame_command | 0x2000;
*(ptrr+7) = in_two_requests | (in_two_requests << 31);
// Set number of frames
*(ptrl+6) = nimages*(2+in_two_requests);
*(ptrr+6) = nimages*(2+in_two_requests);
#ifdef MARTIN
for (i=0; i < 10; i++)
printf("%X\n",*(ptrl+i));
printf("%d\n",in_two_requests);
#endif
close(fd);
#ifdef MARTIN
cprintf(RED, "----Beb_RequestNImages----\n");
#endif
return 1;
}
@ -609,3 +726,35 @@ int Beb_Test(unsigned int beb_number){
return 1;
}
// Returns the FPGA temperature from the xps sysmon ip core
// Temperature value is cropped and not well rounded
int Beb_GetBebFPGATemp()
{
int temperature=0;
volatile u_int32_t *ptr1;
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1)
{
printf("\nCan't find /dev/mem!\n");
return 0;
}
u_int32_t CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, XPAR_SYSMON_0_BASEADDR );
if (CSP0BASE == (u_int32_t)MAP_FAILED)
{
printf("\nCan't map memmory area!!\n");
return 0;
}
ptr1=(u_int32_t*)(CSP0BASE + 0x200); // temperature register in xps sysmon core is at 0x200
close(fd);
temperature = ((((float)(*ptr1)/65536.0f)/0.00198421639f ) - 273.15f); // Static conversation, copied from xps sysmon standalone driver
return temperature;
}

View File

@ -74,12 +74,14 @@ struct BebInfo{
/*int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);*/
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty);
int Beb_StopAcquisition();
int Beb_SetUpTransferParameters(short the_bit_mode);
/*int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait=0); //all images go to the same destination!*/
int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait);
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait);
int Beb_Test(unsigned int beb_number);
int Beb_GetBebFPGATemp();
#endif

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -149,8 +149,10 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition();
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);
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag);
//functions for setting up exposure
void Feb_Control_PrintAcquisitionSetup();

View File

@ -72,7 +72,7 @@ int Feb_Interface_WriteTo(unsigned int ch){
if(ch>0xfff) return 0;
#ifdef MARTIN
printf("FIW ch %d\n", ch);
cprintf(YELLOW, "FIW ch %d\n", ch);
#endif
Feb_Interface_send_data_raw[0] = 0x8fff0000;

View File

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

View File

@ -6,8 +6,6 @@
#include <stdio.h>
#include <unistd.h>
//#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "HardwareMMappingDefs.h"
@ -127,9 +125,9 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
word_ptr = (unsigned int *)buffer;
#ifdef MARTIN
printf("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base);
cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base);
for (i=0; i < buffer_len/4; i++)
printf("%.8X ",*(((unsigned *) buffer)+i));
cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i));
printf("\n");
#endif
@ -139,6 +137,9 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
{
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
#ifdef MARTIN
if (vacancy == 0) cprintf(RED, "Fifo full!\n");
#endif
}
//Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100
@ -173,7 +174,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
int sof = 0;
#ifdef MARTIN
printf("LL Read - If: %X - Data: ",ll->ll_fifo_base);
cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base);
#endif
word_ptr = (unsigned int *)buffer;
@ -202,7 +203,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
if ( (buffer_len >> 2) > buffer_ptr)
{
#ifdef MARTIN
printf("%.8X ", fifo_val);
cprintf(CYAN, "%.8X ", fifo_val);
#endif
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
}
@ -216,7 +217,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
{
len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT );
#ifdef MARTIN
printf("Len: %d\n",len);
cprintf(CYAN, "Len: %d\n",len);
#endif
// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len);
buffer_ptr = 0;

View File

@ -6,8 +6,6 @@
#include <stdio.h>
#include <unistd.h>
//#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "HardwareMMappingDefs.h"

View File

@ -8,6 +8,10 @@
#include "HardwareIO.h"
#include <sys/types.h>
#include "ansi.h"
#include <sys/mman.h>
#include <fcntl.h>
/*class LocalLinkInterface: public HardwareIO{ //*/

View File

@ -1,6 +1,6 @@
CC = powerpc-4xx-softfloat-gcc
CCX = powerpc-4xx-softfloat-g++
CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN
CFLAGS += -Wall -DDACS_INT -DMARTIN -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN
LDLIBS += -lm -lstdc++
PROGS = eigerDetectorServer

View File

@ -495,78 +495,62 @@ enum detectorSettings setSettings(enum detectorSettings sett, int imod){
int startReceiver(int d){
if(master)
//if(master)
Feb_Control_PrepareForAcquisition();
return OK;
}
int startStateMachine(){
int ret;
if(master){
printf("Going to start acquisition\n");
Feb_Control_StartAcquisition();
}
int ret,prev_flag;
//get the DAQ toggle bit
prev_flag = Feb_Control_AcquisitionStartedBit();
//do not read status here, cannot get images then
printf("Going to start acquisition\n");
Feb_Control_StartAcquisition();
////if(trialMasterMode == IS_MASTER){
printf("requesting images\n");
ret = startReadOut();
////}
//if(trialMasterMode == IS_MASTER){
if(master){
/*
* int i=0;
if(getRunStatus() == IDLE){
for(i=0;i<100000;i++){
usleep(1000);
if(getRunStatus() != IDLE){
printf("*****i=%d\n",i);
break;
}
}
//while(getRunStatus() == IDLE);
//}
printf("*****Acquiring...\n");
}
*/
while(getRunStatus() == IDLE);
printf("*****Acquiring...\n");
//wait for acquisition start
if(ret == OK){
if(!Feb_Control_WaitForStartedFlag(5000, prev_flag)){
cprintf(RED,"Error: Acquisition did no start or trouble reading register\n");
ret = FAIL;
}
cprintf(GREEN,"***Acquisition started\n");
}
/*else usleep(1000000);
printf("****Returning\n");*/
/*while(getRunStatus() == IDLE){printf("waiting for being not idle anymore\n");}*/
return ret;
}
int stopStateMachine(){
//if(trialMasterMode == IS_MASTER){
printf("Going to stop acquisition\n");
if(Feb_Control_StopAcquisition())
if(Feb_Control_StopAcquisition() & Beb_StopAcquisition())
return OK;
//}else return OK;
return FAIL;
}
int startReadOut(){
//RequestImages();
int ret_val = 0;
int ret_val = 0, i;
dst_requested[0] = 1;
while(dst_requested[on_dst]){
//waits on data
int beb_num = BEB_NUM;//Feb_Control_GetModuleNumber();
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))))
if ((ret_val = (!Beb_RequestNImages(beb_num,send_to_ten_gig,on_dst,nimages_per_request,0))))
break;
// for(i=0;i<nimages_per_request;i++)
// if ((ret_val = (!Beb_RequestNImages(beb_num,send_to_ten_gig,on_dst,1,0))))
// break;
dst_requested[on_dst++]=0;
on_dst%=ndsts_in_use;
}
@ -598,8 +582,8 @@ enum runStatus getRunStatus(){
char *readFrame(int *ret, char *mess){
//if(master){
if(!Feb_Control_WaitForFinishedFlag(5000))
printf("error in waiting for finished flag\n");
printf("Acquisition finished\n");
cprintf(RED,"Error: Waiting for finished flag\n");
cprintf(GREEN,"Acquisition finished***\n");
//usleep(0);
usleep(1000000);
printf("*****Done Waiting...\n");
@ -1007,4 +991,9 @@ int getAllTrimbits(){
return *((detectorModules->chanregs));
}
int getBebFPGATemp()
{
return Beb_GetBebFPGATemp();
}
#endif

View File

@ -4259,11 +4259,11 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
myDet->startReceiver();
else if(!strcasecmp(args[1],"stop")){
myDet->startReceiverReadout();
runStatus s = myDet->getReceiverStatus();
/*runStatus s = myDet->getReceiverStatus();
while(s != RUN_FINISHED){
usleep(50000);
s = myDet->getReceiverStatus();
}
}*/
myDet->stopReceiver();
}
else

View File

@ -131,6 +131,7 @@ int startReceiver(int d);
void setExternalGating(int enable[]);
void setAllTrimbits(int val);
int getAllTrimbits();
int getBebFPGATemp();
#endif

View File

@ -1244,7 +1244,7 @@ int set_dac(int file_des) {
int get_adc(int file_des) {
int retval;
int retval=-1;
int ret=OK,ret1=OK;
int arg[2];
enum dacIndex ind;
@ -1271,6 +1271,12 @@ int get_adc(int file_des) {
#endif
switch (ind) {
#ifdef EIGERD
case TEMPERATURE_FPGA: //dac = TEMP_FPGA;
retval=getBebFPGATemp();
printf("Temperature: %d°C\n",retval);
break;
#endif
#ifdef GOTTHARDD
case TEMPERATURE_FPGA: //dac = TEMP_FPGA;
break;
@ -1284,7 +1290,7 @@ int get_adc(int file_des) {
break;
}
#ifdef SLS_DETECTOR_FUNCTION_LIST
if (ret==OK) {
if ((ret==OK) && (retval==-1)) {
retval=getADC(idac,imod);
}
#endif

View File

@ -81,9 +81,14 @@ int receiverInterface::sendInt(int fnum, int &retval, int arg){
int receiverInterface::getInt(int fnum, int &retval){
int ret = slsDetectorDefs::FAIL;
char mess[100] = "";
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==slsDetectorDefs::FAIL){
dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Receiver returned error: " << mess << std::endl;
}
dataSocket->ReceiveDataOnly(&retval,sizeof(retval));
dataSocket->Disconnect();