removed eiger detector server to revert to a basic format

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@571 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-05-21 15:30:02 +00:00
parent fa0ae04eb0
commit bc1514edbb
15 changed files with 0 additions and 5965 deletions

View File

@ -1,27 +0,0 @@
CC = powerpc-4xx-softfloat-g++
CLAGS += -Wall -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD #-DVIRTUAL
LDLIBS += -lm -lstdc++
PROGS = eigerDetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRC_CLNT = slsDetectorServer.cpp
SRC_CLNTC = slsDetectorServer_funcs.c communication_funcs.c slsDetector_firmware.c slsDetectorFunctionList.c
OBJS = $(SRC_CLNT:.cpp=.o) $(SRC_CLNTC:%.c=%.o)
all: clean $(PROGS)
boot: $(OBJS)
$(PROGS):
echo $(OBJS)
mkdir -p $(DESTDIR)
$(CC) $(CLAGS) $(SRC_CLNT) $(SRC_CLNTC) $(LDLIBS) -o $@
mv $(PROGS) $(DESTDIR)
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o

View File

@ -1,547 +0,0 @@
#include "communication_funcs.h"
//#include <sys/socket.h>
#include <netinet/tcp.h> /* for TCP_NODELAY */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
//int socketDescriptor, file_des;
const int send_rec_max_size=SEND_REC_MAX_SIZE;
extern int errno;
char dummyClientIP[INET_ADDRSTRLEN];
fd_set readset, tempset;
int isock=0, maxfd;
int myport=-1;
//struct sockaddr_in address;
//#define VERBOSE
int bindSocket(unsigned short int port_number) {
int i;
struct sockaddr_in addressS;
int socketDescriptor;
//int file_des;
//file_des= -1;
if (myport==port_number)
return -10;
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
if (socketDescriptor < 0) {
printf("Can not create socket\n");
} else {
i = 1;
setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
// setsockopt(socketDescriptor, IPPROTO_TCP, TCP_NODELAY, (char *) &i, sizeof(i));
// TCP_CORK
// Set some fields in the serverAddress structure.
addressS.sin_family = AF_INET;
addressS.sin_addr.s_addr = htonl(INADDR_ANY);
addressS.sin_port = htons(port_number);
// memset(&address.sin_addr, 0, sizeof(address.sin_addr));
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){
printf("Can not create socket\n");
socketDescriptor=-1;
} else {
if (listen(socketDescriptor, 5)==0) {
if (isock==0) {
FD_ZERO(&readset);
}
FD_SET(socketDescriptor, &readset);
isock++;
maxfd = socketDescriptor;
printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor);
myport=port_number;
} else
printf("error on listen");
}
}
//int getrlimit(int resource, struct rlimit *rlim);
return socketDescriptor;
}
int getServerError(int socketDescriptor)
{
if (socketDescriptor<0) return 1;
else return 0;
};
int acceptConnection(int socketDescriptor) {
int j;
struct sockaddr_in addressC;
int file_des=-1;
struct timeval tv;
int result;
//socklen_t address_length;
size_t address_length=sizeof(struct sockaddr_in);
if (socketDescriptor<0)
return -1;
memcpy(&tempset, &readset, sizeof(tempset));
tv.tv_sec = 10000000;
tv.tv_usec = 0;
result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
if (result == 0) {
printf("select() timed out!\n");
} else if (result < 0 && errno != EINTR) {
printf("Error in select(): %s\n", strerror(errno));
} else if (result > 0) {
#ifdef VERBOSE
printf("select returned!\n");
#endif
for (j=0; j<maxfd+1; j++) {
if (FD_ISSET(j, &tempset)) {
#ifdef VERBOSE
printf("fd %d is set\n",j);
#endif
FD_CLR(j, &tempset);
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
printf("Error in accept(): %s\n", strerror(errno));
printf("Error: with server accept, connection refused %d\n", errno);
switch(errno) {
case EWOULDBLOCK:
printf("ewouldblock eagain\n");
break;
case EBADF:
printf("ebadf\n");
break;
case ECONNABORTED:
printf("econnaborted\n");
break;
case EFAULT:
printf("efault\n");
break;
case EINTR:
printf("eintr\n");
break;
case EINVAL:
printf("einval\n");
break;
case EMFILE:
printf("emfile\n");
break;
case ENFILE:
printf("enfile\n");
break;
case ENOTSOCK:
printf("enotsock\n");
break;
case EOPNOTSUPP:
printf("eOPNOTSUPP\n");
break;
case ENOBUFS:
printf("ENOBUFS\n");
break;
case ENOMEM:
printf("ENOMEM\n");
break;
case ENOSR:
printf("ENOSR\n");
break;
case EPROTO:
printf("EPROTO\n");
break;
default:
printf("unknown error\n");
}
// should remove descriptor
socketDescriptor=-1;
} else {
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
#ifdef VERBOSE
printf("connection accepted %d\n",file_des);
#endif
FD_SET(file_des, &readset);
maxfd = (maxfd < file_des)?file_des:maxfd;
}
}
}
}
return file_des;
}
void closeConnection(int file_des) {
#ifdef VERY_VERBOSE
#endif
if(file_des>=0)
close(file_des);
FD_CLR(file_des, &readset);
}
void exitServer(int socketDescriptor) {
if (socketDescriptor>=0)
close(socketDescriptor);
#ifdef VERY_VERBOSE
printf("Closing server\n");
#endif
FD_CLR(socketDescriptor, &readset);
socketDescriptor=-1;
isock--;
}
int sendDataOnly(int file_des, void* buf,int length) {
return write(file_des, buf, length);
}
int receiveDataOnly(int file_des, void* buf,int length) {
int total_received=0;
int nreceiving;
int nreceived;
if (file_des<0) return -1;
#ifdef VERY_VERBOSE
printf("want to receive %d Bytes\n", length);
#endif
while(length>0){
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length;
#ifdef VERY_VERBOSE
printf("want to receive %d Bytes\n", nreceiving);
#endif
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
#ifdef VERY_VERBOSE
printf("read %d \n", nreceived);
#endif
if(!nreceived) break;
// if(nreceived<0) break;
length-=nreceived;
total_received+=nreceived;
// cout<<"nrec: "<<nreceived<<" waiting for ("<<length<<")"<<endl;
}
#ifdef VERY_VERBOSE
printf("received %d Bytes\n", total_received);
#endif
if (total_received>0)
strcpy(thisClientIP,dummyClientIP);
//if (strcmp(lastClientIP,"none")==0)
//strcpy(lastClientIP,thisClientIP);
if (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
return total_received;
}
int sendChannel(int file_des, sls_detector_channel *myChan) {
return sendDataOnly(file_des,myChan, sizeof(sls_detector_channel));
}
int sendChip(int file_des, sls_detector_chip *myChip) {
int ts=0;
int nChans=myChip->nchan;
ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip));
ts+=sendDataOnly(file_des,myChip->chanregs,nChans*sizeof(int));
return ts;
}
int sendModule(int file_des, sls_detector_module *myMod) {
int ts=0;
#ifdef VERBOSE
int idac;
#endif
int nChips=myMod->nchip;
int nChans=myMod->nchan;
int nAdcs=myMod->nadc;
int nDacs=myMod->ndac;
ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module));
#ifdef VERBOSE
printf("module %d of size %d sent\n",myMod->module, ts);
#endif
ts+= sendDataOnly(file_des,myMod->dacs,sizeof(dacs_t)*nDacs);
#ifdef VERBOSE
printf("dacs %d of size %d sent\n",myMod->module, ts);
for (idac=0; idac< nDacs; idac++)
printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]);
#endif
ts+= sendDataOnly(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs);
#ifdef VERBOSE
printf("adcs %d of size %d sent\n",myMod->module, ts);
#endif
ts+=sendDataOnly(file_des,myMod->chipregs,sizeof(int)*nChips);
#ifdef VERBOSE
printf("chips %d of size %d sent\n",myMod->module, ts);
#endif
ts+=sendDataOnly(file_des,myMod->chanregs,sizeof(int)*nChans);
#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
return ts;
}
int receiveChannel(int file_des, sls_detector_channel *myChan) {
return receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel));
}
int receiveChip(int file_des, sls_detector_chip* myChip) {
int *ptr=myChip->chanregs;
int ts=0;
int nChans, nchanold=myChip->nchan, chdiff;
ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip));
myChip->chanregs=ptr;
nChans=myChip->nchan;
chdiff=nChans-nchanold;
if (nchanold!=nChans) {
printf("wrong number of channels received!\n");
}
#ifdef VERBOSE
printf("chip structure received\n");
printf("now receiving %d channels\n", nChans);
#endif
if (chdiff<=0)
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nChans);
else {
ptr=(int *)malloc(chdiff*sizeof(int));
myChip->nchan=nchanold;
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(file_des,ptr, sizeof(int)*chdiff);
free(ptr);
return FAIL;
}
#ifdef VERBOSE
printf("chip's channels received\n");
#endif
return ts;
}
int receiveModule(int file_des, sls_detector_module* myMod) {
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;
int nAdcs, naold=myMod->nadc, nadcdiff;
// int id=0;
ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
myMod->dacs=dacptr;
myMod->adcs=adcptr;
myMod->chipregs=chipptr;
myMod->chanregs=chanptr;
nChips=myMod->nchip;
nchipdiff=nChips-nchipold;
if (nchipold!=nChips) {
printf("received wrong number of chips\n");
}
#ifdef VERBOSE
else
printf("received %d chips\n",nChips);
#endif
nChans=myMod->nchan;
nchandiff=nChans-nchanold;
if (nchanold!=nChans) {
printf("received wrong number of channels\n");
}
#ifdef VERBOSE
else
printf("received %d chans\n",nChans);
#endif
nDacs=myMod->ndac;
ndacdiff=nDacs-ndold;
if (ndold!=nDacs) {
printf("received wrong number of dacs\n");
}
#ifdef VERBOSE
else
printf("received %d dacs\n",nDacs);
#endif
nAdcs=myMod->nadc;
nadcdiff=nAdcs-naold;
if (naold!=nAdcs) {
printf("received wrong number of adcs\n");
}
#ifdef VERBOSE
else
printf("received %d adcs\n",nAdcs);
#endif
if (ndacdiff<=0) {
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*nDacs);
#ifdef VERBOSE
printf("dacs received\n");
for (id=0; id<nDacs; id++)
printf("dac %d val %d\n",id, (int)myMod->dacs[id]);
#endif
} else {
dacptr=(dacs_t *)malloc(ndacdiff*sizeof(dacs_t));
myMod->ndac=ndold;
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*ndold);
ts+=receiveDataOnly(file_des,dacptr, sizeof(dacs_t)*ndacdiff);
free(dacptr);
return FAIL;
}
if (nadcdiff<=0) {
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs);
#ifdef VERBOSE
printf("adcs received\n");
#endif
} else {
adcptr=(dacs_t *)malloc(nadcdiff*sizeof(dacs_t));
myMod->nadc=naold;
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*naold);
ts+=receiveDataOnly(file_des,adcptr, sizeof(dacs_t)*nadcdiff);
free(adcptr);
return FAIL;
}
if (nchipdiff<=0) {
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nChips);
#ifdef VERBOSE
printf("chips received\n");
#endif
} else {
chipptr=(int *)malloc(nchipdiff*sizeof(int));
myMod->nchip=nchipold;
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nchipold);
ts+=receiveDataOnly(file_des,chipptr, sizeof(int)*nchipdiff);
free(chipptr);
return FAIL;
}
if (nchandiff<=0) {
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nChans);
#ifdef VERBOSE
printf("chans received\n");
#endif
} else {
chanptr=(int *)malloc(nchandiff*sizeof(int));
myMod->nchan=nchanold;
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(file_des,chanptr, sizeof(int)*nchandiff);
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

@ -1,37 +0,0 @@
#ifndef COMMUNICATION_FUNCS_H
#define COMMUNICATION_FUNCS_H
#define SEND_REC_MAX_SIZE 4096
#define DEFAULT_PORTNO 1952
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include "sls_detector_defs.h"
char lastClientIP[INET_ADDRSTRLEN];
char thisClientIP[INET_ADDRSTRLEN];
int lockStatus;
int differentClients;
int bindSocket(unsigned short int port_number);
int acceptConnection(int socketDescriptor);
void closeConnection(int file_Des);
void exitServer(int socketDescriptor);
int sendDataOnly(int file_des, void* buf,int length);
int receiveDataOnly(int file_des, void* buf,int length);
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 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);
#endif

View File

@ -1,85 +0,0 @@
/*
* registers.h
*
* Created on: Jan 24, 2013
* Author: l_maliakal_d
*/
#ifndef REGISTERS_H_
#define REGISTERS_H_
#include "sls_detector_defs.h"
#define CSP0 0xC4100000 //XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR
#define MEM_SIZE 0xFFFFFFF
#define FIFO_CNTRL_REG 0x0 //PLB_LL_FIFO_REG_CTRL
#define FIFO_STATUS_REG 0x1 //PLB_LL_FIFO_REG_STATUS
#define FIFO_FIFO_REG 0x2 //PLB_LL_FIFO_REG_FIFO
#define FIFO_THRESHOLD_WORDS 100 //PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS
/*Fifo Control Register*/
#define FIFOCNTRL_RESET_MASK 0x0CE00000 //PLB_LL_FIFO_CTRL_RESET_STD
/*Fifo Status Register*/
#define FIFOSTATUS_SOF_BIT 0x10000000 //PLB_LL_FIFO_STATUS_LL_SOF
#define FIFOSTATUS_EOF_BIT 0x20000000 //PLB_LL_FIFO_STATUS_LL_EOF
#define FIFOSTATUS_REM_OFFSET 30 //PLB_LL_FIFO_STATUS_LL_REM_SHIFT
#define FIFOSTATUS_REM_MASK 0xC0000000 //PLB_LL_FIFO_STATUS_LL_REM
#define FIFOSTATUS_EMPTY_BIT 0x08000000 //PLB_LL_FIFO_STATUS_EMPTY
#define FIFOSTATUS_ALMOST_FULL_BIT 0x01000000 //PLB_LL_FIFO_STATUS_ALMOSTFULL
/*Fifo Fifo Register*/
#define FIFOCNTRL_SOF_BIT 0x10000000 //PLB_LL_FIFO_CTRL_LL_SOF
#define FIFOCNTRL_EOF_BIT 0x20000000 //PLB_LL_FIFO_CTRL_LL_EOF
#define FIFOCNTRL_REM_OFFSET 30 //PLB_LL_FIFO_CTRL_LL_REM_SHIFT
#define FIFOCNTRL_REM_MASK 0xC0000000 //PLB_LL_FIFO_CTRL_LL_REM
#define FIFOCNTRL_MASK 0xF0000000 //PLB_LL_FIFO_CTRL_LL_MASK
#define SET_FRAMES_LSB_REG 0x1
#define SET_FRAMES_MSB_REG 0x1
#define GET_FRAMES_LSB_REG 0x1
#define GET_FRAMES_MSB_REG 0x1
#define SET_EXPTIME_LSB_REG 0x1
#define SET_EXPTIME_MSB_REG 0x1
#define GET_EXPTIME_LSB_REG 0x1
#define GET_EXPTIME_MSB_REG 0x1
#define SET_GATES_LSB_REG 0x1
#define SET_GATES_MSB_REG 0x1
#define GET_GATES_LSB_REG 0x1
#define GET_GATES_MSB_REG 0x1
#define SET_PERIOD_LSB_REG 0x1
#define SET_PERIOD_MSB_REG 0x1
#define GET_PERIOD_LSB_REG 0x1
#define GET_PERIOD_MSB_REG 0x1
#define SET_DELAY_LSB_REG 0x1
#define SET_DELAY_MSB_REG 0x1
#define GET_DELAY_LSB_REG 0x1
#define GET_DELAY_MSB_REG 0x1
#define SET_TRAINS_LSB_REG 0x1
#define SET_TRAINS_MSB_REG 0x1
#define GET_TRAINS_LSB_REG 0x1
#define GET_TRAINS_MSB_REG 0x1
#endif /* REGISTERS_H_ */

View File

@ -1,802 +0,0 @@
#ifdef SLS_DETECTOR_FUNCTION_LIST
#include "slsDetectorFunctionList.h"
#include "slsDetectorServer_defs.h"
#include <stdio.h>
#include <string.h>
extern int nModX;
extern int nModBoard;
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;
const int allSelected=-2;
const int noneSelected=-1;
sls_detector_module *detectorModules=NULL;
int *detectorChips=NULL;
int *detectorChans=NULL;
dacs_t *detectorDacs=NULL;
dacs_t *detectorAdcs=NULL;
int initializeDetector(){
int imod;
int n=getNModBoard(X)*getNModBoard(Y);
/*nModX=n;*/
#ifdef VERBOSE
printf("Board is for %d modules\n",n);
#endif
detectorModules=(sls_detector_module *)malloc(n*sizeof(sls_detector_module));
detectorChips=(int *)malloc(n*NCHIP*sizeof(int));
detectorChans=(int *)malloc(n*NCHIP*NCHAN*sizeof(int));
detectorDacs=(dacs_t *)malloc(n*NDAC*sizeof(int));
detectorAdcs=(dacs_t *)malloc(n*NADC*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));
#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)->module=imod;
(detectorModules+imod)->gain=0;
(detectorModules+imod)->offset=0;
(detectorModules+imod)->reg=0;
/* initialize registers, dacs, retrieve sn, adc values etc */
}
thisSettings=UNINITIALIZED;
sChan=noneSelected;
sChip=noneSelected;
sMod=noneSelected;
sDac=noneSelected;
sAdc=noneSelected;
return OK;
}
int setNMod(int nm, enum dimension dim){
return 1;
}
int getNModBoard(enum dimension arg){
return 1;
}
int64_t getModuleId(enum idMode arg, int imod){
//DETECTOR_SERIAL_NUMBER
//DETECTOR_FIRMWARE_VERSION
return 0;
}
int64_t getDetectorId(enum idMode arg){
//DETECTOR_SOFTWARE_VERSION defined in slsDetector_defs.h?
return 0;
}
int moduleTest( enum digitalTestMode arg, int imod){
//template testShiftIn from mcb_funcs.c
//CHIP_TEST
//testShiftIn
//testShiftOut
//testShiftStSel
//testDataInOutMux
//testExtPulseMux
//testOutMux
//testFpgaMux
return OK;
}
int detectorTest( enum digitalTestMode arg){
//templates from firmware_funcs.c
//DETECTOR_FIRMWARE_TEST:testFpga()
//DETECTOR_MEMORY_TEST:testRAM()
//DETECTOR_BUS_TEST:testBus()
//DETECTOR_SOFTWARE_TEST:testFpga()
return OK;
}
double setDAC(enum dacIndex ind, double val, int imod){
//template initDACbyIndexDACU from mcb_funcs.c
//check that slsDetectorServer_funcs.c set_dac() has all the specific dac enums
//set dac and write to a register in fpga to remember dac value when server restarts
return 0;
}
double getADC(enum dacIndex ind, int imod){
//get adc value
return 0;
}
int setChannel(sls_detector_channel myChan){
//template initChannelByNumber() from mcb_funcs.c
return myChan.reg;
}
int getChannel(sls_detector_channel *myChan){
//template getChannelbyNumber() from mcb_funcs.c
return FAIL;
}
int setChip(sls_detector_chip myChip){
//template initChipbyNumber() from mcb_funcs.c
return myChip.reg;
}
int getChip(sls_detector_chip *myChip){
//template getChipbyNumber() from mcb_funcs.c
return FAIL;
}
int setModule(sls_detector_module myChan){
//template initModulebyNumber() from mcb_funcs.c
return OK;
}
int getModule(sls_detector_module *myChan){
//template getModulebyNumber() from mcb_funcs.c
return FAIL;
}
int getThresholdEnergy(int imod){
//template getThresholdEnergy() from mcb_funcs.c
//depending on settings
return FAIL;
}
int setThresholdEnergy(int thr, int imod){
//template getThresholdEnergy() from mcb_funcs.c
//depending on settings
return FAIL;
}
enum detectorSettings setSettings(enum detectorSettings sett, int imod){
//template setSettings() from mcb_funcs.c
//reads the dac registers from fpga to confirm which settings, if weird, undefined
return GET_SETTINGS;
}
int startStateMachine(){
//template startStateMachine() from firmware_funcs.c
/*
fifoReset();
now_ptr=(char*)ram_values;
//send start acquisition to fpga
*/
return FAIL;
}
int stopStateMachine(){
//template stopStateMachine() from firmware_funcs.c
// send stop to fpga
//if status = busy after 500us, return FAIL
return FAIL;
}
int startReadOut(){
//template startReadOut() from firmware_funcs.c
//send fpga start readout
return FAIL;
}
enum runStatus getRunStatus(){
//template runState() from firmware_funcs.c
//get status from fpga
return ERROR;
}
char *readFrame(int *ret, char *mess){
//template fifo_read_event() from firmware_funcs.c
//checks if state machine running and if fifo has data(look_at_me_reg) and accordingly reads frame
// memcpy(now_ptr, values, dataBytes);
//returns ptr to values
return NULL;
}
int64_t setTimer(enum timerIndex ind, int64_t val){
//template setDelay() from firmware_funcs.c
//writes to reg
//FRAME_NUMBER
//ACQUISITION_TIME
//FRAME_PERIOD
//DELAY_AFTER_TRIGGER
//GATES_NUMBER
//PROBES_NUMBER
//CYCLES_NUMBER
return 0;
}
int64_t getTimeLeft(enum timerIndex ind){
//template getDelay() from firmware_funcs.c
//reads from reg
//FRAME_NUMBER
//ACQUISITION_TIME
//FRAME_PERIOD
//DELAY_AFTER_TRIGGER
//GATES_NUMBER
//PROBES_NUMBER
//CYCLES_NUMBER
return -1;
}
int setDynamicRange(int dr){
//template setDynamicRange() from firmware_funcs.c
return 0;
}
int setROI(int mask){ //////?????????????????
return FAIL;
}
int getROI(int *mask){ //////////?????????????????????
return FAIL;
}
int setSpeed(enum speedVariable arg, int val){
//template setClockDivider() from firmware_funcs.c
//CLOCK_DIVIDER
//WAIT_STATES
//SET_SIGNAL_LENGTH
//TOT_CLOCK_DIVIDER
//TOT_DUTY_CYCLE
//returns eg getClockDivider from firmware_funcs.c
return 0;
}
enum readOutFlags setReadOutFlags(enum readOutFlags val){
//template setStoreInRAM from firmware_funcs.c
return GET_READOUT_FLAGS;
}
int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
// template trim_with_noise from trimming_funcs.c
return FAIL;
}
int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb){
//detector specific.
return FAIL;
}
int loadImage(enum imageType index, char *imageVals){
//detector specific.
return FAIL;
}
int readCounterBlock(int startACQ, char *counterVals){
//detector specific.
return FAIL;
}
int resetCounterBlock(int startACQ){
//detector specific.
return FAIL;
}
int calculateDataBytes(){
return 0;
}
int getTotalNumberOfChannels(){return 0;}
int getTotalNumberOfChips(){return 0;}
int getTotalNumberOfModules(){return 0;}
int getNumberOfChannelsPerChip(){return 0;}
int getNumberOfChannelsPerModule(){return 0;}
int getNumberOfChipsPerModule(){return 0;}
int getNumberOfDACsPerModule(){return 0;}
int getNumberOfADCsPerModule(){return 0;}
enum externalSignalFlag getExtSignal(int signalindex){
//template getExtSignal from firmware_funcs.c
//return signals[signalindex];
return GET_EXTERNAL_SIGNAL_FLAG;
}
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag){
//template setExtSignal from firmware_funcs.c
//in short..sets signals array, checks if agrees with timing mode, writes to fpga reg, calls synchronization and then settiming
/*
if (signalindex>=0 && signalindex<4) {
signals[signalindex]=flag;
#ifdef VERBOSE
printf("settings signal variable number %d to value %04x\n", signalindex, signals[signalindex]);
#endif
// if output signal, set it!
switch (flag) {
case GATE_IN_ACTIVE_HIGH:
case GATE_IN_ACTIVE_LOW:
if (timingMode==GATE_FIX_NUMBER || timingMode==GATE_WITH_START_TRIGGER)//timingMode = AUTO_TIMING by default and is set in setTiming()
setFPGASignal(signalindex,flag); //not implemented here, checks if flag within limits and writes to fpga reg
else
setFPGASignal(signalindex,SIGNAL_OFF);
break;
case TRIGGER_IN_RISING_EDGE:
case TRIGGER_IN_FALLING_EDGE:
if (timingMode==TRIGGER_EXPOSURE || timingMode==GATE_WITH_START_TRIGGER)
setFPGASignal(signalindex,flag);
else
setFPGASignal(signalindex,SIGNAL_OFF);
break;
case RO_TRIGGER_IN_RISING_EDGE:
case RO_TRIGGER_IN_FALLING_EDGE:
if (timingMode==TRIGGER_READOUT)
setFPGASignal(signalindex,flag);
else
setFPGASignal(signalindex,SIGNAL_OFF);
break;
case MASTER_SLAVE_SYNCHRONIZATION:
setSynchronization(syncMode);//syncmode = NO_SYNCHRONIZATION by default and set with this function
break;
default:
setFPGASignal(signalindex,mode);
}
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
}
*/
return getExtSignal(signalindex);
}
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
//template setTiming from firmware_funcs.c
//template getFPGASignal from firmware_funcs.c
//getFPGASignal(signalindex) used later on in this fucntion
//gets flag from fpga reg, checks if flag within limits,
//if( flag=SIGNAL_OFF and signals[signalindex]==MASTER_SLAVE_SYNCHRONIZATION), return -1, (ensures masterslaveflag !=off now)
//else return flag
//int ret=(externalCommunicationMode)GET_EXTERNAL_COMMUNICATION_MODE;
//sets timingmode variable
//ensures that the signals are in acceptance with timing mode and according sets the timing mode
/*
int g=-1, t=-1, rot=-1;
int i;
switch (ti) {
case AUTO_TIMING:
timingMode=ti;
// disable all gates/triggers in except if used for master/slave synchronization
for (i=0; i<4; i++) {
if (getFPGASignal(i)>0 && getFPGASignal(i)<GATE_OUT_ACTIVE_HIGH && signals[i]!=MASTER_SLAVE_SYNCHRONIZATION)
setFPGASignal(i,SIGNAL_OFF);
}
break;
case TRIGGER_EXPOSURE:
timingMode=ti;
// if one of the signals is configured to be trigger, set it and unset possible gates
for (i=0; i<4; i++) {
if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,signals[i]);
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
setFPGASignal(i,SIGNAL_OFF);
else if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,SIGNAL_OFF);
}
break;
case TRIGGER_READOUT:
timingMode=ti;
// if one of the signals is configured to be trigger, set it and unset possible gates
for (i=0; i<4; i++) {
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,signals[i]);
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
setFPGASignal(i,SIGNAL_OFF);
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,SIGNAL_OFF);
}
break;
case GATE_FIX_NUMBER:
timingMode=ti;
// if one of the signals is configured to be trigger, set it and unset possible gates
for (i=0; i<4; i++) {
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,SIGNAL_OFF);
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
setFPGASignal(i,signals[i]);
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,SIGNAL_OFF);
}
break;
case GATE_WITH_START_TRIGGER:
timingMode=ti;
for (i=0; i<4; i++) {
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,SIGNAL_OFF);
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
setFPGASignal(i,signals[i]);
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
setFPGASignal(i,signals[i]);
}
break;
default:
;
}
for (i=0; i<4; i++) {
if (signals[i]!=MASTER_SLAVE_SYNCHRONIZATION) {
if (getFPGASignal(i)==RO_TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==RO_TRIGGER_IN_FALLING_EDGE)
rot=i;
else if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH || getFPGASignal(i)==GATE_IN_ACTIVE_LOW)
g=i;
else if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==TRIGGER_IN_FALLING_EDGE)
t=i;
}
}
if (g>=0 && t>=0 && rot<0) {
ret=GATE_WITH_START_TRIGGER;
} else if (g<0 && t>=0 && rot<0) {
ret=TRIGGER_EXPOSURE;
} else if (g>=0 && t<0 && rot<0) {
ret=GATE_FIX_NUMBER;
} else if (g<0 && t<0 && rot>0) {
ret=TRIGGER_READOUT;
} else if (g<0 && t<0 && rot<0) {
ret=AUTO_TIMING;
}
*/
return GET_EXTERNAL_COMMUNICATION_MODE;
}
enum masterFlags setMaster(enum masterFlags arg){
//template setMaster from firmware_funcs.c
/*
int i;
switch(f) {
case NO_MASTER:
// switch of gates or triggers
masterMode=NO_MASTER;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
setFPGASignal(i,SIGNAL_OFF);
}
}
break;
case IS_MASTER:
// configure gate or trigger out
masterMode=IS_MASTER;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
switch (syncMode) {
case NO_SYNCHRONIZATION:
setFPGASignal(i,SIGNAL_OFF);
break;
case MASTER_GATES:
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
break;
case MASTER_TRIGGERS:
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
break;
case SLAVE_STARTS_WHEN_MASTER_STOPS:
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
break;
default:
;
}
}
}
break;
case IS_SLAVE:
// configure gate or trigger in
masterMode=IS_SLAVE;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
switch (syncMode) {
case NO_SYNCHRONIZATION:
setFPGASignal(i,SIGNAL_OFF);
break;
case MASTER_GATES:
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
break;
case MASTER_TRIGGERS:
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
break;
case SLAVE_STARTS_WHEN_MASTER_STOPS:
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
break;
default:
;
}
}
}
break;
default:
//do nothing
;
}
switch(masterMode) {
case NO_MASTER:
return NO_MASTER;
case IS_MASTER:
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
switch (syncMode) {
case NO_SYNCHRONIZATION:
return IS_MASTER;
case MASTER_GATES:
if (getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
return IS_MASTER;
else
return NO_MASTER;
case MASTER_TRIGGERS:
if (getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
return IS_MASTER;
else
return NO_MASTER;
case SLAVE_STARTS_WHEN_MASTER_STOPS:
if (getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
return IS_MASTER;
else
return NO_MASTER;
default:
return NO_MASTER;
}
}
}
case IS_SLAVE:
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
switch (syncMode) {
case NO_SYNCHRONIZATION:
return IS_SLAVE;
case MASTER_GATES:
if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
return IS_SLAVE;
else
return NO_MASTER;
case MASTER_TRIGGERS:
case SLAVE_STARTS_WHEN_MASTER_STOPS:
if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
return IS_SLAVE;
else
return NO_MASTER;
default:
return NO_MASTER;
}
}
}
}
*/
return NO_MASTER;
}
enum synchronizationMode setSynchronization(enum synchronizationMode arg){
/*
int i;
switch(s) {
case NO_SYNCHRONIZATION:
syncMode=NO_SYNCHRONIZATION;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
setFPGASignal(i,SIGNAL_OFF);
}
}
break;
// disable external signals?
case MASTER_GATES:
// configure gate in or out
syncMode=MASTER_GATES;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER)
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
else if (masterMode==IS_SLAVE)
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
}
}
break;
case MASTER_TRIGGERS:
// configure trigger in or out
syncMode=MASTER_TRIGGERS;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER)
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
else if (masterMode==IS_SLAVE)
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
}
}
break;
case SLAVE_STARTS_WHEN_MASTER_STOPS:
// configure trigger in or out
syncMode=SLAVE_STARTS_WHEN_MASTER_STOPS;
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER)
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
else if (masterMode==IS_SLAVE)
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
}
}
break;
default:
//do nothing
;
}
switch (syncMode) {
case NO_SYNCHRONIZATION:
return NO_SYNCHRONIZATION;
case MASTER_GATES:
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER && getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
return MASTER_GATES;
else if (masterMode==IS_SLAVE && getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
return MASTER_GATES;
}
}
return NO_SYNCHRONIZATION;
case MASTER_TRIGGERS:
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER && getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
return MASTER_TRIGGERS;
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
return MASTER_TRIGGERS;
}
}
return NO_SYNCHRONIZATION;
case SLAVE_STARTS_WHEN_MASTER_STOPS:
for (i=0; i<4; i++) {
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
if (masterMode==IS_MASTER && getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
return SLAVE_STARTS_WHEN_MASTER_STOPS;
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
return SLAVE_STARTS_WHEN_MASTER_STOPS;
}
}
return NO_SYNCHRONIZATION;
default:
return NO_SYNCHRONIZATION;
}
*/
return NO_SYNCHRONIZATION;
}
#endif

View File

@ -1,106 +0,0 @@
#ifdef SLS_DETECTOR_FUNCTION_LIST
#ifndef SLS_DETECTOR_FUNCTION_LIST_H
#define SLS_DETECTOR_FUNCTION_LIST_H
#include "sls_detector_defs.h"
#include <stdlib.h>
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
#include <asm/page.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
*/
/****************************************************
This functions are used by the slsDetectroServer_funcs interface.
Here are the definitions, but the actual implementation should be done for each single detector.
****************************************************/
int initializeDetector();
int setNMod(int nm, enum dimension dim);
int getNModBoard(enum dimension arg);
int64_t getModuleId(enum idMode arg, int imod);
int64_t getDetectorId(enum idMode arg);
int moduleTest( enum digitalTestMode arg, int imod);
int detectorTest( enum digitalTestMode arg);
double setDAC(enum dacIndex ind, double val, int imod);
double getADC(enum dacIndex ind, int imod);
int setChannel(sls_detector_channel myChan);
int getChannel(sls_detector_channel *myChan);
int setChip(sls_detector_chip myChip);
int getChip(sls_detector_chip *myChip);
int setModule(sls_detector_module myChan);
int getModule(sls_detector_module *myChan);
int getThresholdEnergy(int imod);
int setThresholdEnergy(int thr, int imod);
enum detectorSettings setSettings(enum detectorSettings sett, int imod);
int startStateMachine();
int stopStateMachine();
int startReadOut();
enum runStatus getRunStatus();
char *readFrame(int *ret, char *mess);
int64_t setTimer(enum timerIndex ind, int64_t val);
int64_t getTimeLeft(enum timerIndex ind);
int setDynamicRange(int dr);
int setROI(int mask); //////?????????????????
int getROI(int *mask); //////////?????????????????????
int setSpeed(enum speedVariable arg, int val);
enum readOutFlags setReadOutFlags(enum readOutFlags val);
int executeTrimming(enum trimMode mode, int par1, int par2, int imod);
int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb);
int loadImage(enum imageType index, char *imageVals);
int readCounterBlock(int startACQ, char *counterVals);
int resetCounterBlock(int startACQ);
int calculateDataBytes();
int getTotalNumberOfChannels();
int getTotalNumberOfChips();
int getTotalNumberOfModules();
int getNumberOfChannelsPerChip();
int getNumberOfChannelsPerModule();
int getNumberOfChipsPerModule();
int getNumberOfDACsPerModule();
int getNumberOfADCsPerModule();
enum externalSignalFlag getExtSignal(int signalindex);
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag);
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg);
enum masterFlags setMaster(enum masterFlags arg);
enum synchronizationMode setSynchronization(enum synchronizationMode arg);
#endif
#endif

View File

@ -1,96 +0,0 @@
/* A simple server in the internet domain using TCP
The port number is passed as an argument */
#include "sls_detector_defs.h"
#include "communication_funcs.h"
#include "slsDetectorServer_funcs.h"
#include "slsDetectorServer_defs.h"
#include <stdio.h>
#include <stdlib.h>
extern int sockfd;
void error(char *msg)
{
perror(msg);
}
int main(int argc, char *argv[])
{
int portno, b;
char cmd[100];
int retval=OK;
int sd, fd;
if (argc==1) {
portno = DEFAULT_PORTNO;
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
printf("opening control server on port %d\n",portno );
/* system(cmd);*/
b=1;
} else {
portno = DEFAULT_PORTNO+1;
if ( sscanf(argv[1],"%d",&portno) ==0) {
printf("could not open stop server: unknown port\n");
return 1;
}
b=0;
printf("opening stop server on port %d\n",portno);
}
init_detector(b); //defined in slsDetectorServer_funcs
sd=bindSocket(portno); //defined in communication_funcs
sockfd=sd;
if (getServerError(sd)) { //defined in communication_funcs
printf("server error!\n");
return -1;
}
/* assign function table */
function_table(); //defined in slsDetectorServer_funcs
#ifdef VERBOSE
printf("function table assigned \n");
#endif
/* waits for connection */
while(retval!=GOODBYE) {
#ifdef VERBOSE
printf("\n");
#endif
#ifdef VERY_VERBOSE
printf("Waiting for client call\n");
#endif
fd=acceptConnection(sockfd); //defined in communication_funcs
#ifdef VERY_VERBOSE
printf("Conenction accepted\n");
#endif
if (fd>0) {
retval=decode_function(fd); //defined in slsDetectorServer_funcs
#ifdef VERY_VERBOSE
printf("function executed\n");
#endif
closeConnection(fd); //defined in communication_funcs
#ifdef VERY_VERBOSE
printf("connection closed\n");
#endif
}
}
exitServer(sockfd); //defined in communication_funcs
printf("Goodbye!\n");
return 0;
}

View File

@ -1,31 +0,0 @@
/*
* slsDetectorServer_defs.h
*
* Created on: Jan 24, 2013
* Author: l_maliakal_d
*/
#ifndef SLSDETECTORSERVER_DEFS_H_
#define SLSDETECTORSERVER_DEFS_H_
#include "sls_detector_defs.h"
#include <stdint.h>
#define GOODBYE -200
#define NCHAN 1
#define NCHIP 1
#define NDAC 1
#define NADC 1
#define NMAXMODX 1
#define NMAXMODY 1
#define NMAXMOD NMAXMODX*NMAXMODY
#define NCHANS NCHAN*NCHIP*NMAXMOD
#define NDACS NDAC*NMAXMOD
#define DYNAMIC_RANGE 16
#define CLK_FREQ 100E+6
#endif /* SLSDETECTORSERVER_DEFS_H_ */

View File

@ -1,82 +0,0 @@
#ifndef SERVER_FUNCS_H
#define SERVER_FUNCS_H
#include "sls_detector_defs.h"
#include <stdlib.h>
int sockfd;
int function_table();
int swap_int32(int val);
int64_t swap_int64(int64_t val);
int decode_function(int);
//if b>0 all the detector must be initialized, otherwise it is just the stop server
int init_detector(int);
int M_nofunc(int);
int exit_server(int);
// General purpose functions
int get_detector_type(int);
int set_number_of_modules(int);
int get_max_number_of_modules(int);
int exec_command(int);
int set_external_signal_flag(int);
int set_external_communication_mode(int);
int get_id(int);
int digital_test(int);
int write_register(int);
int read_register(int);
int set_dac(int);
int get_adc(int);
int set_channel(int);
int set_chip(int);
int set_module(int);
int get_channel(int);
int get_chip(int);
int get_module(int);
int get_threshold_energy(int);
int set_threshold_energy(int);
int set_settings(int);
int start_acquisition(int);
int stop_acquisition(int);
int start_readout(int);
int get_run_status(int);
int read_frame(int);
int read_all(int);
int start_and_read_all(int);
int set_timer(int);
int get_time_left(int);
int set_dynamic_range(int);
int set_roi(int);
int get_roi(int);
int set_speed(int);
int set_readout_flags(int);
int execute_trimming(int);
int lock_server(int);
int set_port(int);
int get_last_client_ip(int);
int set_master(int);
int set_synchronization(int);
int configure_mac(int);
int load_image(int);
int read_counter_block(int);
int reset_counter_block(int);
int update_client(int);
int send_update(int);
#endif

View File

@ -1,387 +0,0 @@
#include "sls_detector_defs.h"
#include "slsDetector_firmware.h"
#include "slsDetectorServer_defs.h"
#include "registers.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h> //PROT_READ,PROT_WRITE,MAP_FILE,MAP_SHARED,MAP_FAILED
#include <fcntl.h> //O_RDWR
u_int32_t CSP0BASE;
u_int32_t fifo_control_reg;
int nModBoard;
int nModY = NMAXMOD;
int nModX = NMAXMOD;
int dynamicRange= DYNAMIC_RANGE;
int dataBytes = NMAXMOD*NCHIP*NCHAN*2;
int masterMode = NO_MASTER;
int syncMode = NO_SYNCHRONIZATION;
int timingMode = AUTO_TIMING;
#ifdef SLS_DETECTOR_FUNCTION_LIST
extern const int nChans;
extern const int nChips;
extern const int nDacs;
extern const int nAdcs;
#endif
#ifndef SLS_DETECTOR_FUNCTION_LIST
const int nChans = NCHAN;
const int nChips = NCHIP;
const int nDacs = NDAC;
const int nAdcs = NADC;
#endif
int64_t dummy=0;
/* Gerd example
if ((fd=open("/dev/mem", O_RDWR)) < 0){
printf("Cant find /dev/mem!\n");
return FAIL;
}
printf("/dev/mem opened\n");
void *plb_ll_fifo_ptr;
plb_ll_fifo_ptr = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, CSP0);
if (plb_ll_fifo_ptr == MAP_FAILED){
printf("\nCan't map memmory area!!\n");
return FAIL;
}
CSP0BASE = (u_int32_t) plb_ll_fifo_ptr;
//plb_ll_fifo_ctrl_reg = 0;
*/
int mapCSP0(void) {
int fd;
printf("Mapping memory\n");
#ifdef VIRTUAL
CSP0BASE = (u_int32_t)malloc(MEM_SIZE);
printf("memory allocated\n");
#else
if ((fd=open("/dev/mem", O_RDWR | O_SYNC)) < 0){
printf("Cant find /dev/mem!\n");
return FAIL;
}
printf("/dev/mem opened\n");
CSP0BASE = (u_int32_t)mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
printf("\nCan't map memmory area!!\n");
return FAIL;
}
#endif
printf("CSPOBASE is 0x%x \n",CSP0BASE);
printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
fifo_control_reg = 0;
return OK;
}
u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
__asm__ volatile ("stw %0,0(%1); eieio"::"r" (data), "b"(CSP0BASE+4*offset));
return OK;
}
u_int32_t bus_r(u_int32_t offset) {
u_int32_t ptr1;
__asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (ptr1):"b"(CSP0BASE+4*offset));
return ptr1;
}
int fifoReset(){
u_int32_t mask = FIFOCNTRL_RESET_MASK;
fifo_control_reg |= mask;
//printf("CTRL Register bits: 0x%08x\n",fifo_control_reg);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
fifo_control_reg &= (~mask);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
printf("fifo has been reset\n\n");
return OK;
}
int fifoTest(void){
int buffer_length = 256;
int rec_buffer_length = 4096;
char cmd[] = "help";
unsigned int buffer[buffer_length];
unsigned int rec_buffer[rec_buffer_length];
unsigned int send_len;
int rec_len;
char *char_ptr;
char_ptr = (char *)buffer;
//fill the buffer with numbers for(i=0; i < BUFF_LEN; i++) {char_ptr[i]=i+1;}
//sending command
strcpy(char_ptr,cmd);
send_len = strlen(cmd);
fifoSend(char_ptr,send_len);
// printf("status : 0x%08x \n",PLB_LL_fifo_get_status_vector());
usleep(10000);
do{
rec_len = fifoReceive(rec_buffer,rec_buffer_length);
if (rec_len > 0){
//printf("receive buffer 0x%08x length: %i\n",rec_buffer,rec_len);
char_ptr = (char*) &rec_buffer[0];
char_ptr[rec_len]=0;
printf(char_ptr);
}
} while(rec_len > 0);
return OK;
}
// note: buffer must be word (4 byte) aligned, frameLength in byte
int fifoSend(void *buffer, unsigned int frameLength){
int vacancy=0;
int i;
int words_send = 0;
int last_word;
unsigned int *word_ptr;
unsigned int val,mask;
u_int32_t status;
if (frameLength < 1)
return -1;
/**4?*/
last_word = (frameLength-1)/4;
word_ptr = (unsigned int *)buffer;
/*what does this do*/
while (words_send <= last_word){
//wait for Fifo to be empty again
while (!vacancy){
status = bus_r(FIFO_STATUS_REG);
if(!(status & FIFOSTATUS_ALMOST_FULL_BIT))
vacancy = 1;
}
/**fifo threshold words?*/
for (i=0; ((i<FIFO_THRESHOLD_WORDS) && (words_send <= last_word)); i++){
val = 0;
//announce the start of file
if (words_send == 0)
val = FIFOCNTRL_SOF_BIT;
if (words_send == last_word) /**rem_offset??*/
val |= (FIFOCNTRL_EOF_BIT | (( (frameLength-1)<<FIFOCNTRL_REM_OFFSET) & FIFOCNTRL_REM_MASK) );
//control reg write mask
mask = FIFOCNTRL_MASK;
fifo_control_reg &= (~mask);
fifo_control_reg |= ( mask & val);
bus_w(FIFO_CNTRL_REG,fifo_control_reg);
bus_w(FIFO_FIFO_REG,word_ptr[words_send++]);
}
}
return frameLength;
}
int fifoReceive(void *buffer, unsigned int bufflen){
static unsigned int buffer_ptr = 0;
int len;
unsigned int *word_ptr;
unsigned int status;
volatile unsigned int fifo_val;
int sof = 0;
word_ptr = (unsigned int *)buffer;
//repeat while fifo status not empty
do{
status = bus_r(FIFO_STATUS_REG);
if (!(status & FIFOSTATUS_EMPTY_BIT)){
if (status & FIFOSTATUS_SOF_BIT){
//if SOF, buffer_ptr should be zero, else buffer overflow
if (buffer_ptr){
buffer_ptr = 0;
return -1;
}
// printf(">>>> SOF\n\r");
buffer_ptr = 0;/**not needed */
sof = 1;
}
//read from fifo
fifo_val = bus_r(FIFO_FIFO_REG);
if ((buffer_ptr > 0) || sof){
if ( (bufflen >> 2) > buffer_ptr)
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
else{
buffer_ptr = 0;
return -2; // buffer overflow
}
if (status & FIFOSTATUS_EOF_BIT){
len = (buffer_ptr << 2) -3 + ( (status & FIFOSTATUS_REM_MASK)>>FIFOSTATUS_REM_OFFSET );
// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len);
buffer_ptr = 0;
return len;
}
}
}
}
while(!(status & FIFOSTATUS_EMPTY_BIT));
return OK;
}
int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
int64_t v64;
u_int32_t vLSB,vMSB;
if (value!=-1) {
vLSB=value&(0xffffffff);
bus_w(aLSB,vLSB);
v64=value>> 32;
vMSB=v64&(0xffffffff);
bus_w(aMSB,vMSB);
}
return get64BitReg(aLSB, aMSB);
}
int64_t get64BitReg(int aLSB, int aMSB){
int64_t v64;
u_int32_t vLSB,vMSB;
vLSB=bus_r(aLSB);
vMSB=bus_r(aMSB);
v64=vMSB;
v64=(v64<<32) | vLSB;
return v64;
}
int64_t setFrames(int64_t value){//dummy = value;return dummy;
return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
}
int64_t getFrames(){//return dummy;
return get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG);
}
int64_t setExposureTime(int64_t value){
/* time is in ns */
if (value!=-1)
value*=(int64_t)(1E-9*CLK_FREQ);
return (int64_t)(set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t getExposureTime(){
return (int64_t)(get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t setGates(int64_t value){
return set64BitReg(value, SET_GATES_LSB_REG, SET_GATES_MSB_REG);
}
int64_t getGates(){
return get64BitReg(GET_GATES_LSB_REG, GET_GATES_MSB_REG);
}
int64_t setPeriod(int64_t value){
/* time is in ns */
if (value!=-1)
value*=(int64_t)(1E-9*CLK_FREQ);
return (int64_t)(set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t getPeriod(){
return (int64_t)(get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t setDelay(int64_t value){
/* time is in ns */
if (value!=-1) {
value*=(int64_t)(1E-9*CLK_FREQ);
}
return (int64_t)(set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t getDelay(){
return (int64_t)(get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ));
}
int64_t setTrains(int64_t value){
return set64BitReg(value, SET_TRAINS_LSB_REG, SET_TRAINS_MSB_REG);
}
int64_t getTrains(){
return get64BitReg(GET_TRAINS_LSB_REG, GET_TRAINS_MSB_REG);
}
int64_t setProbes(int64_t value){
return 0;
}
int64_t getProbes(){
return 0;
}

View File

@ -1,179 +0,0 @@
/*
* slsDetector_firmware.h
*
* Created on: Jan 24, 2013
* Author: l_maliakal_d
*/
#ifndef SLSDETECTOR_FIRMWARE_H_
#define SLSDETECTOR_FIRMWARE_H_
#include "sls_detector_defs.h"
#include <stdlib.h>
//memory
int mapCSP0(void);
u_int32_t bus_w(u_int32_t offset, u_int32_t data);
u_int32_t bus_r(u_int32_t offset);
int fifoReset();
int fifoTest(void);
int fifoSend(void *buffer, unsigned int frame_len);
int fifoReceive(void *buffer, unsigned int bufflen);
//Acquisition Parameters
int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
int64_t get64BitReg(int aLSB, int aMSB);
int64_t setFrames(int64_t value);
int64_t getFrames();
int64_t setExposureTime(int64_t value);
int64_t getExposureTime();
int64_t setGates(int64_t value);
int64_t getGates();
int64_t setDelay(int64_t value);
int64_t getDelay();
int64_t setPeriod(int64_t value);
int64_t getPeriod();
int64_t setTrains(int64_t value);
int64_t getTrains();
int64_t setProbes(int64_t value);
int64_t getProbes();
/*
u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function
u_int32_t bus_r(u_int32_t offset);
int setPhaseShiftOnce();
int cleanFifo();
int setDAQRegister(int adcval);
u_int32_t putout(char *s, int modnum);
u_int32_t readin(int modnum);
u_int32_t setClockDivider(int d);
u_int32_t getClockDivider();
u_int32_t setSetLength(int d);
u_int32_t getSetLength();
u_int32_t setWaitStates(int d);
u_int32_t getWaitStates();
u_int32_t setTotClockDivider(int d);
u_int32_t getTotClockDivider();
u_int32_t setTotDutyCycle(int d);
u_int32_t getTotDutyCycle();
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
int getExtSignal(int d);
u_int32_t setFPGASignal(int d, enum externalSignalFlag mode);
int getFPGASignal(int d);
int setTiming(int t);
int setConfigurationRegister(int d);
int setToT(int d);
int setContinousReadOut(int d);
int startReceiver(int d);
int setDACRegister(int idac, int val, int imod);
int getTemperature(int tempSensor,int imod);
int initHighVoltage(int val,int imod);
int initConfGain(int isettings,int val,int imod);
int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int adc,int udpport);
int getAdcConfigured();
u_int64_t getDetectorNumber();
u_int32_t getFirmwareVersion();
int testFifos(void);
u_int32_t testFpga(void);
u_int32_t testRAM(void);
int testBus(void);
int setDigitalTestBit(int ival);
int64_t getProgress();
int64_t setProgress();
int64_t getActualTime();
int64_t getMeasurementTime();
u_int32_t runBusy(void);
u_int32_t runState(void);
u_int32_t dataPresent(void);
int startStateMachine();
int stopStateMachine();
int startReadOut();
u_int32_t fifoReset(void);
u_int32_t fifoReadCounter(int fifonum);
u_int32_t fifoReadStatus();
u_int32_t fifo_full(void);
u_int32_t* fifo_read_event();
u_int32_t* decode_data(int* datain);
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
int setDynamicRange(int dr);
int getDynamicRange();
int getNModBoard();
int setNMod(int n);
int setStoreInRAM(int b);
int allocateRAM();
int clearRAM();
int setMaster(int f);
int setSynchronization(int s);
int loadImage(int index, short int ImageVals[]);
int readCounterBlock(int startACQ, short int CounterVals[]);
int resetCounterBlock(int startACQ);
u_int32_t setNBits(u_int32_t);
u_int32_t getNBits();
*/
/*
//move to mcb_funcs?
int readOutChan(int *val);
u_int32_t getModuleNumber(int modnum);
int testShiftIn(int imod);
int testShiftOut(int imod);
int testShiftStSel(int imod);
int testDataInOut(int num, int imod);
int testExtPulse(int imod);
int testExtPulseMux(int imod, int ow);
int testDataInOutMux(int imod, int ow, int num);
int testOutMux(int imod);
int testFpgaMux(int imod);
int calibration_sensor(int num, int *values, int *dacs) ;
int calibration_chip(int num, int *values, int *dacs);
*/
#endif /* SLSDETECTOR_FIRMWARE_H_ */

View File

@ -1,46 +0,0 @@
/* A simple server in the internet domain using TCP
The port number is passed as an argument */
#include "communication_funcs.h"
#include "slsDetectorFunctionList.h"/*#include "slsDetector_firmware.h" for the time being*/
#include "slsDetectorServer_defs.h"
//#include <stdio.h>
//#include <stdlib.h>
int sockfd;
int main(int argc, char *argv[])
{
int portno;
int retval=0;
// int sd,fd;
portno = DEFAULT_PORTNO;
bindSocket(portno); //defined in communication_funcs
if (getServerError()) //defined in communication_funcs
return -1;
/* waits for connection */
while(retval!=GOODBYE) {
#ifdef VERBOSE
printf("\n");
#endif
#ifdef VERY_VERBOSE
printf("Stop server: waiting for client call\n");
#endif
acceptConnection(); //defined in communication_funcs
retval=stopStateMachine();//defined in slsDetectorFirmare_funcs
closeConnection(); //defined in communication_funcs
}
exitServer(); //defined in communication_funcs
printf("Goodbye!\n");
return 0;
}

View File

@ -1,554 +0,0 @@
#ifndef SLS_DETECTOR_DEFS_H
#define SLS_DETECTOR_DEFS_H
#ifdef __CINT__
#define MYROOT
#define __cplusplus
#endif
#include <stdint.h>
/** default maximum string length */
#define MAX_STR_LENGTH 1000
/** default maximum string length */
#define MAX_SCAN_STEPS 2000
/** maxmimum number of modules per controller*/
#define MAXMODS 24
/** maxmimum number of detectors ina multidetector structure*/
#define MAXDET 100
/** header length for data :gotthard*/
#define HEADERLENGTH 12
/** maximum rois */
#define MAX_ROIS 100
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
typedef char mystring[MAX_STR_LENGTH];
typedef double mysteps[MAX_SCAN_STEPS];
#ifdef DACS_INT
typedef int dacs_t;
#else
typedef float dacs_t;
#endif
#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee"
#define DEFAULT_DET_IP "129.129.202.46"
#define MAX_FRAMES_PER_FILE 20000
#define SHORT_MAX_FRAMES_PER_FILE 100000
/**
\file sls_detector_defs.h
This file contains all the basic definitions common to the slsDetector class
and to the server programs running on the detector
* @author Anna Bergamaschi
* @version 0.1alpha (any string)
* @see slsDetector
$Revision: 464 $
*/
/** get flag form most functions */
#define GET_FLAG -1
#ifdef MYROOT
/** @short class containing all the structures, constants and enum definitions */
class slsDetectorDefs {
public:
slsDetectorDefs(){};
#endif
enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS};
/**
@short structure for a detector channel
should not be used by unexperienced users
\see ::channelRegisterBit
*/
typedef struct {
int chan; /**< is the channel number */
int chip; /**< is the chip number */
int module; /**< is the module number */
int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */
} sls_detector_channel;
/**
@short structure for a detector chip
should not be used by unexperienced users
\see ::chipRegisterBit ::channelRegisterBit
*/
typedef struct {
int chip; /**< is the chip number */
int module; /**< is the module number */
int nchan; /**< is the number of channels in the chip */
int reg; /**<is the chip register (e.g. output analogue buffer enable)
\see ::chipRegisterBit */
int *chanregs; /**< is the pointer to the array of the channel registers
\see ::channelRegisterBit */
} sls_detector_chip;
/**
@short structure for a detector module
should not be used by unexperienced users
\see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit
@li reg is the module register (e.g. dynamic range? see moduleRegisterBit)
@li dacs is the pointer to the array of dac values (in V)
@li adcs is the pointer to the array of adc values (in V)
@li chipregs is the pointer to the array of chip registers
@li chanregs is the pointer to the array of channel registers
@li gain is the module gain
@li offset is the module offset
*/
typedef struct {
int module; /**< is the module number */
int serialnumber; /**< is the module serial number */
int nchan; /**< is the number of channels per chip */
int nchip; /**< is the number of chips on the module */
int ndac; /**< is the number of dacs on the module */
int nadc; /**< is the number of adcs on the module */
int reg; /**< is the module register (e.g. dynamic range?)
\see moduleRegisterBit */
dacs_t *dacs; /**< is the pointer to the array of the dac values (in V) */
dacs_t *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/
int *chipregs; /**< is the pointer to the array of the chip registers
\see ::chipRegisterBit */
int *chanregs; /**< is the pointer to the array of the channel registers
\see ::channelRegisterBit */
double gain; /**< is the module gain (V/keV) */
double offset; /**< is the module offset (V) */
} sls_detector_module;
/**
@short structure for a region of interest
xmin,xmax,ymin,ymax define the limits of the region
*/
typedef struct {
int xmin; /**< is the roi xmin (in channel number) */
int xmax; /**< is the roi xmax (in channel number)*/
int ymin; /**< is the roi ymin (in channel number)*/
int ymax; /**< is the roi ymax (in channel number)*/
} ROI ;
/* /\* */
/* @short structure for a generic integer array */
/* *\/ */
/* typedef struct { */
/* int len; /\**< is the number of elements of the array *\/ */
/* int *iptr; /\**< is the pointer to the array *\/ */
/* } iarray ; */
/**
Type of the detector
*/
enum detectorType {
GET_DETECTOR_TYPE=-1, /**< the detector will return its type */
GENERIC, /**< generic sls detector */
MYTHEN, /**< mythen */
PILATUS, /**< pilatus */
EIGER, /**< eiger */
GOTTHARD, /**< gotthard */
PICASSO, /**< picasso */
AGIPD /**< agipd */
};
/* /\** */
/* Communication protocol (normally TCP) */
/* *\/ */
/* enum communicationProtocol{ */
/* TCP, /\**< TCP/IP *\/ */
/* UDP /\**< UDP *\/ */
/* }; */
/**
network parameters
*/
enum networkParameter {
DETECTOR_MAC, /**< detector MAC */
DETECTOR_IP, /**< detector IP */
RECEIVER_HOSTNAME, /**< receiver IP/hostname */
RECEIVER_UDP_IP, /**< receiever UDP IP */
RECEIVER_UDP_PORT, /**< receiever UDP Port */
RECEIVER_UDP_MAC /**< receiever UDP MAC */
};
/**
type of action performed (for text client)
*/
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION};
/** online flags enum \sa setOnline*/
enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */
OFFLINE_FLAG=0, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */
ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */
};
/**
flags to get (or set) the size of the detector
*/
enum numberOf {
MAXMODX, /**<maximum number of module in X direction */
MAXMODY, /**<maximum number of module in Y direction */
NMODX, /**<installed number of module in X direction */
NMODY, /**<installed number of module in Y direction */
NCHANSX, /**<number of channels in X direction */
NCHANSY, /**<number of channels in Y direction */
NCHIPSX, /**<number of chips in X direction */
NCHIPSY /**<number of chips in Y direction */
};
/**
dimension indexes
*/
enum dimension {
X=0, /**< X dimension */
Y=1, /**< Y dimension */
Z=2 /**< Z dimension */
};
/**
return values
*/
enum {
OK, /**< function succeeded */
FAIL, /**< function failed */
FINISHED, /**< acquisition finished */
FORCE_UPDATE
};
/**
enable/disable flags
*/
enum {
DISABLED, /**<flag disabled */
ENABLED /**<flag enabled */
};
/**
use of the external signals
*/
enum externalSignalFlag {
GET_EXTERNAL_SIGNAL_FLAG=-1, /**<return flag for signal */
SIGNAL_OFF, /**<signal unused - tristate*/
GATE_IN_ACTIVE_HIGH, /**<input gate active high*/
GATE_IN_ACTIVE_LOW, /**<input gate active low */
TRIGGER_IN_RISING_EDGE, /**<input exposure trigger on rising edge */
TRIGGER_IN_FALLING_EDGE, /**<input exposure trigger on falling edge */
RO_TRIGGER_IN_RISING_EDGE, /**<input raedout trigger on rising edge */
RO_TRIGGER_IN_FALLING_EDGE, /**<input readout trigger on falling edge */
GATE_OUT_ACTIVE_HIGH, /**<output active high when detector is exposing*/
GATE_OUT_ACTIVE_LOW, /**<output active low when detector is exposing*/
TRIGGER_OUT_RISING_EDGE, /**<output trigger rising edge at start of exposure */
TRIGGER_OUT_FALLING_EDGE, /**<output trigger falling edge at start of exposure */
RO_TRIGGER_OUT_RISING_EDGE, /**<output trigger rising edge at start of readout */
RO_TRIGGER_OUT_FALLING_EDGE, /**<output trigger falling edge at start of readout */
OUTPUT_LOW, /**< output always low */
OUTPUT_HIGH, /**< output always high */
MASTER_SLAVE_SYNCHRONIZATION /**< reserved for master/slave synchronization in multi detector systems */
};
/**
communication mode using external signals
*/
enum externalCommunicationMode{
GET_EXTERNAL_COMMUNICATION_MODE=-1,/**<return flag for communication mode */
AUTO_TIMING, /**< internal timing */
TRIGGER_EXPOSURE, /**< trigger mode i.e. exposure is triggered */
TRIGGER_FRAME, /**< each trigger triggers one frame at a time */
TRIGGER_READOUT, /**< stop trigger mode i.e. readout is triggered by external signal */
GATE_FIX_NUMBER, /**< gated and reads out after a fixed number of gates */
GATE_WITH_START_TRIGGER, /**< gated with start trigger */
TRIGGER_WINDOW /**< exposure time coincides with the external signal */
};
/**
detector IDs/versions
*/
enum idMode{
MODULE_SERIAL_NUMBER, /**<return module serial number */
MODULE_FIRMWARE_VERSION, /**<return module firmware */
DETECTOR_SERIAL_NUMBER, /**<return detector system serial number */
DETECTOR_FIRMWARE_VERSION, /**<return detector system firmware version */
DETECTOR_SOFTWARE_VERSION, /**<return detector system software version */
THIS_SOFTWARE_VERSION, /**<return this software version */
RECEIVER_VERSION /**<return receiver software version */
};
/**
detector digital test modes
*/
enum digitalTestMode {
CHIP_TEST, /**< test chips */
MODULE_FIRMWARE_TEST, /**< test module firmware */
DETECTOR_FIRMWARE_TEST, /**< test detector system firmware */
DETECTOR_MEMORY_TEST, /**< test detector system memory */
DETECTOR_BUS_TEST, /**< test detector system CPU-FPGA bus */
DETECTOR_SOFTWARE_TEST, /**< test detector system software */
DIGITAL_BIT_TEST /**< gotthard digital bit test */
};
/**
detector analogue test modes
*/
enum analogTestMode {
CALIBRATION_PULSES, /**< test using calibration pulses */
MY_ANALOG_TEST_MODE /**< other possible test modes */
};
/**
detector dacs indexes
*/
enum dacIndex {
THRESHOLD, /**< comparator threshold level */
CALIBRATION_PULSE, /**< calibration input pulse height */
TRIMBIT_SIZE, /**< voltage to determine the trimbits LSB */
PREAMP, /**< preamp feedback */
SHAPER1, /**< shaper1 feedback */
SHAPER2, /**< shaper2 feedback */
TEMPERATURE_ADC, /**< temperature sensor (adc) */
TEMPERATURE_FPGA, /**< temperature sensor (fpga) */
HUMIDITY, /**< humidity sensor (adc) */
DETECTOR_BIAS,/**< detector bias */
VA_POT, /**< power supply va */
VDD_POT, /**< chiptest board power supply vdd */
VSH_POT, /**< chiptest board power supply vsh */
VIO_POT, /**< chiptest board power supply va */
HV_POT, /**< gotthard, chiptest board high voltage */
G_VREF_DS, /**< gotthard */
G_VCASCN_PB, /**< gotthard */
G_VCASCP_PB, /**< gotthard */
G_VOUT_CM, /**< gotthard */
G_VCASC_OUT, /**< gotthard */
G_VIN_CM, /**< gotthard */
G_VREF_COMP, /**< gotthard */
G_IB_TESTC /**< gotthard */
};
/**
detector settings indexes
*/
enum detectorSettings{
GET_SETTINGS=-1, /**< return current detector settings */
STANDARD, /**< standard settings */
FAST, /**< fast settings */
HIGHGAIN, /**< highgain settings */
DYNAMICGAIN, /**< dynamic gain settings */
LOWGAIN, /**< low gain settings */
MEDIUMGAIN, /**< medium gain settings */
VERYHIGHGAIN, /**< very high gain settings */
UNDEFINED, /**< undefined or custom settings */
UNINITIALIZED /**< uninitialiazed (status at startup) */
};
/**
meaning of the channel register bits
\see ::sls_detector_channel
*/
enum channelRegisterBit {
TRIMBIT_OFF=0, /**< offset of trimbit value in the channel register */
COMPARATOR_ENABLE=0x100, /**< mask of the comparator enable bit */
ANALOG_SIGNAL_ENABLE=0x200, /**< mask of the analogue output enable bit */
CALIBRATION_ENABLE=0x300, /**< mask of the calibration input enable bit */
};
#define TRIMBITMASK 0x3f
/**
meaning of the chip register bits
\see ::sls_detector_chip
*/
enum chipRegisterBit {
ENABLE_ANALOG_OUTPUT=0x1, /**< mask of the analogue output enable bit */
CHIP_OUTPUT_WIDTH=0x2 /**< mask of the chip output width */
};
/**
meaning of the module register bits
*/
enum moduleRegisterBit {
MY_MODULE_REGISTER_BIT, /**< possible module register bit meaning */
MODULE_OUTPUT_WIDTH /**< possibly module dynamic range */
};
/**
indexes for the acquisition timers
*/
enum timerIndex {
FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
ACQUISITION_TIME, /**< exposure time */
FRAME_PERIOD, /**< period between exposures */
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
GATES_NUMBER, /**< number of gates per frame (in gated mode) */
PROBES_NUMBER, /**< number of probe types in pump-probe mode */
CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
ACTUAL_TIME, /**< Actual time of the detector's internal timer */
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
PROGRESS, /**< fraction of measurement elapsed - only get! */
MEASUREMENTS_NUMBER
};
/**
important speed parameters
*/
enum speedVariable {
CLOCK_DIVIDER, /**< readout clock divider */
WAIT_STATES, /**< wait states for bus read */
TOT_CLOCK_DIVIDER, /**< wait states for bus read */
TOT_DUTY_CYCLE, /**< wait states for bus read */
SET_SIGNAL_LENGTH /**< set/clear signal length */
};
/**
staus mask
*/
enum runStatus {
IDLE, /**< detector ready to start acquisition - no data in memory */
ERROR, /**< error i.e. normally fifo full */
WAITING, /**< waiting for trigger or gate signal */
RUN_FINISHED, /**< acquisition not running but data in memory */
TRANSMITTING, /**< acquisition running and data in memory */
RUNNING /**< acquisition running, no data in memory */
};
/**
readout flags
*/
enum readOutFlags {
GET_READOUT_FLAGS=-1, /**< return readout flags */
NORMAL_READOUT=0, /**< no flag */
STORE_IN_RAM=0x1, /**< data are stored in ram and sent only after end of acquisition for faster frame rate */
READ_HITS=0x2, /**< return only the number of the channel which counted ate least one */
ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */
PUMP_PROBE_MODE=0x8,/**<pump-probe mode */
BACKGROUND_CORRECTIONS=0x1000, /**<background corrections */
TOT_MODE=0x2000,/**<pump-probe mode */
CONTINOUS_RO=0x4000/**<pump-probe mode */
};
/**
trimming modes
*/
enum trimMode {
NOISE_TRIMMING, /**< trim with noise */
BEAM_TRIMMING, /**< trim with x-rays (on all 63 bits) */
IMPROVE_TRIMMING, /**< trim with x-rays (on a limited range of bits - should start from an already trimmed mode) */
FIXEDSETTINGS_TRIMMING,/**< trim without optimizing the threshold and the trimbit size */
OFFLINE_TRIMMING /**< trimming is performed offline */
};
/**
data correction flags
*/
enum correctionFlags {
DISCARD_BAD_CHANNELS, /**< bad channels are discarded */
AVERAGE_NEIGHBOURS_FOR_BAD_CHANNELS, /**< bad channels are replaced with the avergae of the neighbours */
FLAT_FIELD_CORRECTION, /**< data are flat field corrected */
RATE_CORRECTION, /**< data are rate corrected */
ANGULAR_CONVERSION,/**< angular conversion is calculated */
WRITE_FILE,
I0_NORMALIZATION
};
/** port type */
enum portType {
CONTROL_PORT, /**< control port */
STOP_PORT, /**<stop port */
DATA_PORT /**< receiver tcp port with client*/
};
/** hierarchy in multi-detector structure, if any */
enum masterFlags {
GET_MASTER=-1, /**< return master flag */
NO_MASTER, /**< no master/slave hierarchy defined */
IS_MASTER, /**<is master */
IS_SLAVE /**< is slave */
};
/** synchronization in a multidetector structure, if any */
enum synchronizationMode {
GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */
NO_SYNCHRONIZATION, /**< all detectors are independent (no cabling) */
MASTER_GATES, /**< the master gates the other detectors */
MASTER_TRIGGERS, /**< the master triggers the other detectors */
SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */
};
enum imageType {
DARK_IMAGE, /**< dark image */
GAIN_IMAGE /**< gain image */
};
/* /\** */
/* angular conversion constant for a module */
/* *\/ */
/* typedef struct { */
/* double center; /\**< center of the module (channel at which the radius is perpendicular to the module surface) *\/ */
/* double ecenter; /\**< error in the center determination *\/ */
/* double r_conversion; /\**< detector pixel size (or strip pitch) divided by the diffractometer radius *\/ */
/* double er_conversion; /\**< error in the r_conversion determination *\/ */
/* double offset; /\**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 *\/ */
/* double eoffset; /\**< error in the offset determination *\/ */
/* double tilt; /\**< ossible tilt in the orthogonal direction (unused)*\/ */
/* double etilt; /\**< error in the tilt determination *\/ */
/* } angleConversionConstant; */
enum angleConversionParameter {
ANGULAR_DIRECTION, /**< angular direction of the diffractometer */
GLOBAL_OFFSET, /**< global offset of the diffractometer */
FINE_OFFSET, /**< fine offset of the diffractometer */
BIN_SIZE, /**< angular bin size */
MOVE_FLAG, /**< wether the detector moves with the motor or not in a multi detector system */
SAMPLE_X, /**< sample displacement in the beam direction */
SAMPLE_Y /**< sample displacement orthogonal to the beam */
};
//typedef struct {
//float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */
//float ecenter; /**< error in the center determination */
//float r_conversion; /**< detector pixel size (or strip pitch) divided by the diffractometer radius */
//float er_conversion; /**< error in the r_conversion determination */
//float offset; /**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 */
//float eoffset; /**< error in the offset determination */
//float tilt; /**< ossible tilt in the orthogonal direction (unused)*/
//float etilt; /**< error in the tilt determination *//
//} angleConversionConstant;
#ifdef MYROOT
protected:
#endif
#ifndef MYROOT
#include "sls_detector_funcs.h"
#endif
#ifdef MYROOT
};
#endif
;
#endif
;

View File

@ -1,138 +0,0 @@
/**
@internal
function indexes to call on the server
All set functions with argument -1 work as get, when possible
*/
#ifndef SLS_DETECTOR_FUNCS_H
#define SLS_DETECTOR_FUNCS_H
enum {
// General purpose functions
F_EXEC_COMMAND=0, /**< command is executed */
F_GET_ERROR, /**< return detector error status */
// configuration functions
F_GET_DETECTOR_TYPE, /**< return detector type */
F_SET_NUMBER_OF_MODULES, /**< set/get number of installed modules */
F_GET_MAX_NUMBER_OF_MODULES, /**< get maximum number of installed modules */
F_SET_EXTERNAL_SIGNAL_FLAG, /**< set/get flag for external signal */
F_SET_EXTERNAL_COMMUNICATION_MODE, /**< set/get external communication mode (obsolete) */
// Tests and identification
F_GET_ID, /**< get detector id of version */
F_DIGITAL_TEST, /**< digital test of the detector */
F_ANALOG_TEST, /**<analog test of the detector */
F_ENABLE_ANALOG_OUT, /**<enable the analog output */
F_CALIBRATION_PULSE, /**<pulse the calibration input */
// Initialization functions
F_SET_DAC, /**< set DAC value */
F_GET_ADC, /**< get ADC value */
F_WRITE_REGISTER, /**< write to register */
F_READ_REGISTER, /**< read register */
F_WRITE_MEMORY, /**< write to memory */
F_READ_MEMORY, /**< read memory */
F_SET_CHANNEL, /**< initialize channel */
F_GET_CHANNEL, /**< get channel register */
F_SET_ALL_CHANNELS, /**< initialize all channels */
F_SET_CHIP, /**< initialize chip */
F_GET_CHIP, /**< get chip status */
F_SET_ALL_CHIPS, /**< initialize all chips */
F_SET_MODULE, /**< initialize module */
F_GET_MODULE, /**< get module status */
F_SET_ALL_MODULES, /**< initialize all modules */
F_SET_SETTINGS, /**< set detector settings */
F_GET_THRESHOLD_ENERGY, /**< get detector threshold (in eV) */
F_SET_THRESHOLD_ENERGY, /**< set detector threshold (in eV) */
// Acquisition functions
F_START_ACQUISITION, /**< start acquisition */
F_STOP_ACQUISITION, /**< stop acquisition */
F_START_READOUT, /**< start readout */
F_GET_RUN_STATUS, /**< get acquisition status */
F_START_AND_READ_ALL, /**< start acquisition and read all frames*/
F_READ_FRAME, /**< read one frame */
F_READ_ALL, /**< read alla frames */
//Acquisition setup functions
F_SET_TIMER, /**< set/get timer value */
F_GET_TIME_LEFT, /**< get current value of the timer (time left) */
F_SET_DYNAMIC_RANGE, /**< set/get detector dynamic range */
F_SET_READOUT_FLAGS, /**< set/get readout flags */
F_SET_ROI, /**< set/get region of interest */
F_SET_SPEED, /**< set/get readout speed parameters */
//Trimming
F_EXECUTE_TRIMMING, /**< execute trimming */
F_EXIT_SERVER, /**< turn off detector server */
F_LOCK_SERVER, /**< Locks/Unlocks server communication to the given client */
F_GET_LAST_CLIENT_IP, /**< returns the IP of the client last connected to the detector */
F_SET_PORT, /**< Changes communication port of the server */
F_UPDATE_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */
F_CONFIGURE_MAC, /**< Configures MAC for Gotthard readout */
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
// multi detector structures
F_SET_MASTER, /**< sets master/slave flag for multi detector structures */
F_SET_SYNCHRONIZATION_MODE, /**< sets master/slave synchronization mode for multidetector structures */
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
//receiver
F_SET_FILE_PATH, /**< sets receiver file directory */
F_SET_FILE_NAME, /**< sets receiver file name */
F_SET_FILE_INDEX, /**< sets receiver file index */
F_START_RECEIVER, /**< starts the receiver listening mode */
F_STOP_RECEIVER, /**< stops the receiver listening mode */
F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */
F_GET_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */
F_GET_FRAME_INDEX, /**< gets the frame index */
F_RESET_FRAMES_CAUGHT, /**< resets the frames caught */
F_SETUP_UDP, /**< sets the receiver udp connection and returns receiver mac address */
F_ENABLE_FILE_WRITE /**< sets the receiver file write */
/* Always append functions hereafter!!! */
};
#endif
/** @endinternal */