mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-05 17:40:40 +02:00
gotthard server: made gotthard server readout only via udp, readframe just waits for acquisition to be done, does not allocate ram, receiver: removed positions hardcoded in 1d, should be 2d for all
This commit is contained in:
parent
c2db073d5e
commit
f9b95b63eb
@ -1 +0,0 @@
|
|||||||
../slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.2
|
|
1
serverBin/gotthardDetectorServerv4.0.0.3
Symbolic link
1
serverBin/gotthardDetectorServerv4.0.0.3
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3
|
@ -2,4 +2,4 @@
|
|||||||
#define APIRECEIVER 0x180823
|
#define APIRECEIVER 0x180823
|
||||||
#define APIEIGER 0x180820
|
#define APIEIGER 0x180820
|
||||||
#define APIJUNGFRAU 0x180823
|
#define APIJUNGFRAU 0x180823
|
||||||
#define APIGOTTHARD 0x180925
|
#define APIGOTTHARD 0x180927
|
||||||
|
@ -16,7 +16,7 @@ INSTMODE= 0777
|
|||||||
|
|
||||||
|
|
||||||
BINS = testlib_sharedlibc
|
BINS = testlib_sharedlibc
|
||||||
SRCS = server.c firmware_funcs.c server_funcs.c communication_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
SRCS = server.c firmware_funcs.c server_funcs.c communication_funcs.c mcb_funcs.c
|
||||||
OBJS = $(SRCS:%.c=%.o)
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ INSTMODE= 0777
|
|||||||
|
|
||||||
|
|
||||||
BINS = testlib_sharedlibc
|
BINS = testlib_sharedlibc
|
||||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c
|
||||||
OBJS = $(SRCS:%.c=%.o)
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ CFLAGS += -Wall -DGOTTHARDD -DMCB_FUNCS -DDACS_INT -DDEBUG -DVIRTUAL
|
|||||||
PROGS= $(DESTDIR)/gotthardDetectorServer_virtual
|
PROGS= $(DESTDIR)/gotthardDetectorServer_virtual
|
||||||
|
|
||||||
|
|
||||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c
|
||||||
OBJS = $(SRCS:%.c=%.o)
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
gotthardVirtualServer = $(PROGS)
|
gotthardVirtualServer = $(PROGS)
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
#include "mcb_funcs.h"
|
#include "mcb_funcs.h"
|
||||||
#include "registers_g.h"
|
#include "registers_g.h"
|
||||||
|
|
||||||
#ifdef SHAREDMEMORY
|
|
||||||
#include "sharedmemory.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -34,9 +30,7 @@ int dataBytes=NMAXMOD*NCHIP*NCHAN*2;
|
|||||||
int storeInRAM=0;
|
int storeInRAM=0;
|
||||||
int ROI_flag=0;
|
int ROI_flag=0;
|
||||||
int adcConfigured=-1;
|
int adcConfigured=-1;
|
||||||
u_int32_t *ram_values=NULL;
|
|
||||||
volatile char *now_ptr=NULL;
|
|
||||||
volatile u_int16_t *values;
|
|
||||||
int ram_size=0;
|
int ram_size=0;
|
||||||
|
|
||||||
int64_t totalTime=1;
|
int64_t totalTime=1;
|
||||||
@ -189,9 +183,6 @@ int mapCSP0(void) {
|
|||||||
printf("CSPObase is 0x%llx \n",CSP0BASE);
|
printf("CSPObase is 0x%llx \n",CSP0BASE);
|
||||||
printf("CSPOBASE=from %llx to %llx\n",CSP0BASE,CSP0BASE+MEM_SIZE);
|
printf("CSPOBASE=from %llx to %llx\n",CSP0BASE,CSP0BASE+MEM_SIZE);
|
||||||
|
|
||||||
u_int32_t address;
|
|
||||||
address = FIFO_DATA_REG_OFF;
|
|
||||||
values=(u_int16_t*)(CSP0BASE+address*2);
|
|
||||||
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
return OK;
|
return OK;
|
||||||
@ -851,18 +842,6 @@ u_int32_t testFpga(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// for fpga test
|
|
||||||
u_int32_t testRAM(void) {
|
|
||||||
int result=OK;
|
|
||||||
int i=0;
|
|
||||||
allocateRAM();
|
|
||||||
// while(i<100000) {
|
|
||||||
memcpy((char*)ram_values, (char*)values, dataBytes);
|
|
||||||
printf ("Testing RAM:\t%d: copied fifo %x to memory %x size %d\n",i++, (unsigned int)(values), (unsigned int)(ram_values), dataBytes);
|
|
||||||
// }
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getNModBoard() {
|
int getNModBoard() {
|
||||||
return nModX;
|
return nModX;
|
||||||
}
|
}
|
||||||
@ -1503,11 +1482,7 @@ int startStateMachine(){
|
|||||||
//#endif
|
//#endif
|
||||||
cleanFifo();
|
cleanFifo();
|
||||||
// fifoReset();
|
// fifoReset();
|
||||||
now_ptr=(char*)ram_values;
|
|
||||||
#ifdef SHAREDMEMORY
|
|
||||||
write_stop_sm(0);
|
|
||||||
write_status_sm("Started");
|
|
||||||
#endif
|
|
||||||
bus_w16(CONTROL_REG, START_ACQ_BIT | START_EXPOSURE_BIT);
|
bus_w16(CONTROL_REG, START_ACQ_BIT | START_EXPOSURE_BIT);
|
||||||
bus_w16(CONTROL_REG, 0x0);
|
bus_w16(CONTROL_REG, 0x0);
|
||||||
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
printf("statusreg=%08x\n",bus_r(STATUS_REG));
|
||||||
@ -1583,31 +1558,12 @@ u_int32_t fifo_full(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u_int32_t* fifo_read_event()
|
void waitForAcquisitionFinish(){
|
||||||
{
|
volatile u_int32_t t = bus_r(LOOK_AT_ME_REG);
|
||||||
#ifdef VIRTUAL
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("before looping\n");
|
|
||||||
#endif
|
|
||||||
volatile u_int32_t t = bus_r(LOOK_AT_ME_REG);
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("lookatmereg=x%x\n",t);
|
printf("lookatmereg=x%x\n",t);
|
||||||
#endif
|
#endif
|
||||||
/*
|
while((t&0x1)==0) {
|
||||||
while ((t&0x1)==0)
|
|
||||||
{
|
|
||||||
t = bus_r(LOOK_AT_ME_REG);
|
|
||||||
if (!runBusy()){
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
while((t&0x1)==0) {
|
|
||||||
if (runBusy()==0) {
|
if (runBusy()==0) {
|
||||||
t = bus_r(LOOK_AT_ME_REG);
|
t = bus_r(LOOK_AT_ME_REG);
|
||||||
if ((t&0x1)==0) {
|
if ((t&0x1)==0) {
|
||||||
@ -1615,7 +1571,7 @@ u_int32_t* fifo_read_event()
|
|||||||
printf("no frame found - exiting ");
|
printf("no frame found - exiting ");
|
||||||
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return;
|
||||||
} else {
|
} else {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
|
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
|
||||||
@ -1624,38 +1580,12 @@ u_int32_t* fifo_read_event()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t = bus_r(LOOK_AT_ME_REG);
|
t = bus_r(LOOK_AT_ME_REG);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
dma_memcpy(now_ptr,values ,dataBytes);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERYVERBOSE
|
|
||||||
int a;
|
|
||||||
for (a=0;a<8; a=a+2)
|
|
||||||
printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) );
|
|
||||||
for (a=2554;a<2560; a=a+2)
|
|
||||||
printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) );
|
|
||||||
printf("********\n");
|
|
||||||
//memcpy(now_ptr, values, dataBytes);
|
|
||||||
#endif
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes);
|
|
||||||
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (storeInRAM>0) {
|
|
||||||
now_ptr+=dataBytes;
|
|
||||||
}
|
}
|
||||||
return ram_values;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
u_int32_t* decode_data(int *datain)
|
u_int32_t* decode_data(int *datain)
|
||||||
{
|
{
|
||||||
u_int32_t *dataout;
|
u_int32_t *dataout;
|
||||||
@ -1770,83 +1700,10 @@ int testBus() {
|
|||||||
|
|
||||||
|
|
||||||
int setStoreInRAM(int b) {
|
int setStoreInRAM(int b) {
|
||||||
if (b>0)
|
return 0;
|
||||||
storeInRAM=1;
|
|
||||||
else
|
|
||||||
storeInRAM=0;
|
|
||||||
return allocateRAM();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int allocateRAM() {
|
|
||||||
size_t size;
|
|
||||||
u_int32_t nt, nf;
|
|
||||||
nt=setTrains(-1);
|
|
||||||
nf=setFrames(-1);
|
|
||||||
if (nt==0) nt=1;
|
|
||||||
if (nf==0) nf=1;
|
|
||||||
// ret=clearRAM();
|
|
||||||
if (storeInRAM) {
|
|
||||||
size=dataBytes*nf*nt;
|
|
||||||
if (size<dataBytes)
|
|
||||||
size=dataBytes;
|
|
||||||
} else
|
|
||||||
size=dataBytes;
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("\nnmodx=%d nmody=%d dynamicRange=%d dataBytes=%d nFrames=%d nTrains=%d, size=%d\n",nModX,nModY,dynamicRange,dataBytes,nf,nt,(int)size );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (size==ram_size) {
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("RAM of size %d already allocated: nothing to be done\n",(int) size);
|
|
||||||
#endif
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("reallocating ram %x\n",(unsigned int)ram_values);
|
|
||||||
#endif
|
|
||||||
// clearRAM();
|
|
||||||
// ram_values=malloc(size);
|
|
||||||
//+2 was added since dma_memcpy would switch the 16 bit values and the mem is 32 bit
|
|
||||||
ram_values=realloc(ram_values,size)+2;
|
|
||||||
|
|
||||||
if (ram_values) {
|
|
||||||
now_ptr=(char*)ram_values;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size));
|
|
||||||
#endif
|
|
||||||
ram_size=size;
|
|
||||||
return OK;
|
|
||||||
} else {
|
|
||||||
printf("could not allocate %d bytes\n",(int)size);
|
|
||||||
if (storeInRAM==1) {
|
|
||||||
printf("retrying\n");
|
|
||||||
storeInRAM=0;
|
|
||||||
size=dataBytes;
|
|
||||||
ram_values=realloc(ram_values,size)+2;
|
|
||||||
if (ram_values==NULL)
|
|
||||||
printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n");
|
|
||||||
else {
|
|
||||||
now_ptr=(char*)ram_values;
|
|
||||||
ram_size=size;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n");
|
|
||||||
}
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int configureADC(){
|
int configureADC(){
|
||||||
@ -1908,78 +1765,9 @@ int configureADC(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
/*
|
|
||||||
codata=0;
|
|
||||||
codata=(0x14<<8)+(0x0); //command and value;
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // start point
|
|
||||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_SPI_REG,valw); //chip sel bar down
|
|
||||||
for (i=0;i<24;i++) {
|
|
||||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_SPI_REG,valw);usleep(0); //cldwn
|
|
||||||
|
|
||||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_SPI_REG,valw); usleep(0); //write data (i)
|
|
||||||
|
|
||||||
valw=valw+(0x1<<cdx);bus_w(ADC_SPI_REG,valw); usleep(0); //clkup
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // stop point =start point
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
usleep(5000);
|
|
||||||
|
|
||||||
codata=0;
|
|
||||||
codata=(0x08<<8)+(0x3); //command and value;Power modes(global) reset
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // start point
|
|
||||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_SPI_REG,valw); //chip sel bar down
|
|
||||||
for (i=0;i<24;i++) {
|
|
||||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_SPI_REG,valw);usleep(0); //cldwn
|
|
||||||
|
|
||||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_SPI_REG,valw); usleep(0); //write data (i)
|
|
||||||
valw=valw+(0x1<<cdx);bus_w(ADC_SPI_REG,valw); usleep(0); //clkup
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // stop point =start point
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
usleep(50000);
|
|
||||||
codata=0;
|
|
||||||
codata=(0x08<<8)+(0x0); //command and value;Power modes(global) reset
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // start point
|
|
||||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_SPI_REG,valw); //chip sel bar down
|
|
||||||
for (i=0;i<24;i++) {
|
|
||||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_SPI_REG,valw);usleep(0); //cldwn
|
|
||||||
|
|
||||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_SPI_REG,valw); usleep(0); //write data (i)
|
|
||||||
valw=valw+(0x1<<cdx);bus_w(ADC_SPI_REG,valw); usleep(0); //clkup
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
|
||||||
valw=0xff; bus_w(ADC_SPI_REG,(valw)); // stop point =start point
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int clearRAM() {
|
|
||||||
if (ram_values) {
|
|
||||||
//#ifdef VERBOSE
|
|
||||||
//printf("clearing RAM 0x%x\n", ram_values);
|
|
||||||
//#endif
|
|
||||||
free(ram_values);
|
|
||||||
ram_values=NULL;
|
|
||||||
now_ptr=NULL;
|
|
||||||
}
|
|
||||||
//#ifdef VERBOSE
|
|
||||||
//printf("done 0x%x\n", ram_values);
|
|
||||||
//#endif
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2127,113 +1915,7 @@ int resetCounterBlock(int startACQ){
|
|||||||
|
|
||||||
|
|
||||||
int calibratePedestal(int frames){
|
int calibratePedestal(int frames){
|
||||||
printf("---------------------------\n");
|
// removed this functionlity as it requires reading via cpu
|
||||||
printf("In Calibrate Pedestal\n");
|
|
||||||
int64_t framesBefore = getFrames();
|
|
||||||
int64_t periodBefore = getPeriod();
|
|
||||||
setFrames(frames);
|
|
||||||
setPeriod(1000000);
|
|
||||||
int dataret = OK;
|
|
||||||
|
|
||||||
double avg[1280];
|
|
||||||
int numberFrames = 0;
|
|
||||||
|
|
||||||
int adc = 3;
|
|
||||||
int adcCh = 3;
|
|
||||||
int Ch = 3;
|
|
||||||
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for(i =0; i < 1280; i++){
|
|
||||||
|
|
||||||
avg[i] = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
startReceiver(0);
|
|
||||||
|
|
||||||
startStateMachine();
|
|
||||||
|
|
||||||
while(dataret==OK){
|
|
||||||
//got data
|
|
||||||
if (fifo_read_event()) {
|
|
||||||
dataret=OK;
|
|
||||||
//sendDataOnly(file_des,&dataret,sizeof(dataret));
|
|
||||||
//sendDataOnly(file_des,dataretval,dataBytes);
|
|
||||||
printf("received frame\n");
|
|
||||||
|
|
||||||
unsigned short *frame = (unsigned short *)now_ptr;
|
|
||||||
|
|
||||||
int a;
|
|
||||||
for (a=0;a<1280; a++){
|
|
||||||
//unsigned short v = (frame[a] << 8) + (frame[a] >> 8);
|
|
||||||
// printf("%i: %i %i\n",a, frame[a],v);
|
|
||||||
avg[a] += ((double)frame[a])/(double)frames;
|
|
||||||
//if(frame[a] == 8191)
|
|
||||||
// printf("ch %i: %u\n",a,frame[a]);
|
|
||||||
}
|
|
||||||
// printf("********\n");
|
|
||||||
numberFrames++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//no more data or no data
|
|
||||||
else {
|
|
||||||
if(getFrames()>-2) {
|
|
||||||
dataret=FAIL;
|
|
||||||
printf("no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
dataret=FINISHED;
|
|
||||||
printf("acquisition successfully finished\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
printf("dataret %d\n",dataret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//double nf = (double)numberFrames;
|
|
||||||
for(i =0; i < 1280; i++){
|
|
||||||
adc = i / 256;
|
|
||||||
adcCh = (i - adc * 256) / 32;
|
|
||||||
Ch = i - adc * 256 - adcCh * 32;
|
|
||||||
adc--;
|
|
||||||
double v2 = avg[i];
|
|
||||||
avg[i] = avg[i]/ ((double)numberFrames/(double)frames);
|
|
||||||
unsigned short v = (unsigned short)avg[i];
|
|
||||||
printf("setting avg for channel %i(%i,%i,%i): %i (double= %f (%f))\t", i,adc,adcCh,Ch, v,avg[i],v2);
|
|
||||||
v=i*100;
|
|
||||||
ram_w16(DARK_IMAGE_REG,adc,adcCh,Ch,v-4096);
|
|
||||||
if(ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch) != v-4096){
|
|
||||||
printf("value is wrong (%i,%i,%i): %i \n",adc,adcCh,Ch, ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*for(adc = 1; adc < 5; adc++){
|
|
||||||
for(adcCh = 0; adcCh < 8; adcCh++){
|
|
||||||
for(Ch=0 ; Ch < 32; Ch++){
|
|
||||||
int channel = (adc+1) * 32 * 8 + adcCh * 32 + Ch;
|
|
||||||
double v2 = avg[channel];
|
|
||||||
avg[channel] = avg[channel]/ ((double)numberFrames/(double)frames);
|
|
||||||
unsigned short v = (unsigned short)avg[channel];
|
|
||||||
printf("setting avg for channel %i: %i (double= %f (%f))\t", channel, v,avg[channel],v2);
|
|
||||||
ram_w16(DARK_IMAGE_REG,adc,adcCh,Ch,v-4096);
|
|
||||||
if(ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch) != v-4096){
|
|
||||||
printf("value is wrong (%i,%i,%i): %i \n",adc,adcCh,Ch, ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("frames: %i\n",numberFrames);
|
|
||||||
printf("corrected avg by: %f\n",(double)numberFrames/(double)frames);
|
|
||||||
|
|
||||||
printf("restoring previous condition\n");
|
|
||||||
setFrames(framesBefore);
|
|
||||||
setPeriod(periodBefore);
|
|
||||||
|
|
||||||
printf("---------------------------\n");
|
printf("---------------------------\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ u_int32_t getFirmwareVersion();
|
|||||||
u_int32_t getFirmwareSVNVersion();
|
u_int32_t getFirmwareSVNVersion();
|
||||||
int testFifos(void);
|
int testFifos(void);
|
||||||
u_int32_t testFpga(void);
|
u_int32_t testFpga(void);
|
||||||
u_int32_t testRAM(void);
|
|
||||||
int testBus(void);
|
int testBus(void);
|
||||||
int setDigitalTestBit(int ival);
|
int setDigitalTestBit(int ival);
|
||||||
|
|
||||||
@ -128,8 +127,8 @@ u_int32_t fifoReadStatus();
|
|||||||
u_int32_t fifo_full(void);
|
u_int32_t fifo_full(void);
|
||||||
|
|
||||||
|
|
||||||
|
void waitForAcquisitionFinish();
|
||||||
|
|
||||||
u_int32_t* fifo_read_event();
|
|
||||||
u_int32_t* decode_data(int* datain);
|
u_int32_t* decode_data(int* datain);
|
||||||
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
|
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
|
||||||
int setDynamicRange(int dr);
|
int setDynamicRange(int dr);
|
||||||
@ -137,8 +136,7 @@ int getDynamicRange();
|
|||||||
int getNModBoard();
|
int getNModBoard();
|
||||||
int setNMod(int n);
|
int setNMod(int n);
|
||||||
int setStoreInRAM(int b);
|
int setStoreInRAM(int b);
|
||||||
int allocateRAM();
|
|
||||||
int clearRAM();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
Path: slsDetectorsPackage/slsDetectorSoftware/gotthardDetectorServer
|
Path: slsDetectorsPackage/slsDetectorSoftware/gotthardDetectorServer
|
||||||
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||||
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||||
Repsitory UUID: 4aa0d26f26a16d48ddd265128f02b39e7140127f
|
Repsitory UUID: c2db073d5e936d64733ba9bdfdce311a556ae212
|
||||||
Revision: 239
|
Revision: 241
|
||||||
Branch: 4.0.0
|
Branch: 4.0.0
|
||||||
Last Changed Author: Dhanya_Thattil
|
Last Changed Author: Dhanya_Thattil
|
||||||
Last Changed Rev: 4005
|
Last Changed Rev: 4018
|
||||||
Last Changed Date: 2018-09-25 12:19:12.000000002 +0200 ./server_funcs.h
|
Last Changed Date: 2018-09-27 16:32:41.000000002 +0200 ./firmware_funcs.c
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
|
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
|
||||||
#define GITREPUUID "4aa0d26f26a16d48ddd265128f02b39e7140127f"
|
#define GITREPUUID "c2db073d5e936d64733ba9bdfdce311a556ae212"
|
||||||
#define GITAUTH "Dhanya_Thattil"
|
#define GITAUTH "Dhanya_Thattil"
|
||||||
#define GITREV 0x4005
|
#define GITREV 0x4018
|
||||||
#define GITDATE 0x20180925
|
#define GITDATE 0x20180927
|
||||||
#define GITBRANCH "4.0.0"
|
#define GITBRANCH "4.0.0"
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3
Executable file
BIN
slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3
Executable file
Binary file not shown.
@ -107,7 +107,6 @@ int initDetector() {
|
|||||||
// initChip(0, 0,ALLMOD);
|
// initChip(0, 0,ALLMOD);
|
||||||
//nModX=n;
|
//nModX=n;
|
||||||
//
|
//
|
||||||
allocateRAM();
|
|
||||||
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@ -1831,205 +1830,19 @@ int testDataInOut(int num, int imod) {
|
|||||||
|
|
||||||
|
|
||||||
int testExtPulse(int imod) {
|
int testExtPulse(int imod) {
|
||||||
int i, ichan, ichip, result=OK;
|
// reading via cPU doesnt work, so removed this functionality
|
||||||
int *val1;
|
|
||||||
|
|
||||||
printf("Testing counter for module %d\n", imod);
|
|
||||||
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
putout("0000100000000000",ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
for (i=0; i<NCHAN; i++) {
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
putout("0000000000001000",ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
extPulse(1,ALLMOD);
|
|
||||||
}
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
|
|
||||||
|
|
||||||
// Readout with SM
|
|
||||||
|
|
||||||
//startStateMachine();
|
|
||||||
startReadOut();
|
|
||||||
usleep(100);
|
|
||||||
val1=(int*)(decode_data((int*)(fifo_read_event())));
|
|
||||||
// val1=fifo_read_event();
|
|
||||||
//imod=0;
|
|
||||||
//for (imod=0; imod<nModX; imod++) {
|
|
||||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
|
||||||
for (ichan=0; ichan<NCHAN; ichan++) {//
|
|
||||||
if ((*(val1+ichan+(ichip+imod*NCHIP)*NCHAN))!=ichan) {
|
|
||||||
result++;
|
|
||||||
printf("Counter test: channel %d read %d instead of %d\n",ichan+(ichip+imod*NCHIP)*NCHAN, val1[ichan+(ichip+imod*NCHIP)*NCHAN], ichan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
free(val1);
|
|
||||||
if (result)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int testExtPulseMux(int imod, int ow) {
|
int testExtPulseMux(int imod, int ow) {
|
||||||
|
// reading via cPU doesnt work, so removed this functionality
|
||||||
int i, ichan, ichip, result=0, ind, chipr=0;
|
|
||||||
int *values, *v1;
|
|
||||||
int vright,v;
|
|
||||||
int nbit_mask=0xffffff;
|
|
||||||
|
|
||||||
printf("Testing counter for module %d, mux %d\n", imod, ow);
|
|
||||||
setExposureTime(0);
|
|
||||||
setFrames(1);
|
|
||||||
setTrains(1);
|
|
||||||
|
|
||||||
|
|
||||||
if (ow==2)
|
|
||||||
nbit_mask=0xffff;
|
|
||||||
else if (ow==3)
|
|
||||||
nbit_mask=0xff;
|
|
||||||
else if (ow==4)
|
|
||||||
nbit_mask=0xf;
|
|
||||||
else if (ow==5)
|
|
||||||
nbit_mask=0x1;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
initChipWithProbes(0, ow,0,ALLMOD);
|
|
||||||
// initChip(0, ow,ALLMOD);
|
|
||||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
for (i=0; i<NCHAN; i++) {
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
putout("0000000000001000",ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
extPulse(1,ALLMOD);
|
|
||||||
}
|
|
||||||
nextChip(ALLMOD);
|
|
||||||
}
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
|
|
||||||
// Readout with SM
|
|
||||||
|
|
||||||
|
|
||||||
startReadOut();
|
|
||||||
usleep(100);
|
|
||||||
v1=(int*)(fifo_read_event());
|
|
||||||
if (v1)
|
|
||||||
values=(int*)(decode_data(v1));
|
|
||||||
else {
|
|
||||||
printf("no data found in fifos\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
|
||||||
chipr=0;
|
|
||||||
for (ichan=0; ichan<NCHAN; ichan++) {
|
|
||||||
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
|
|
||||||
v=values[ind];
|
|
||||||
vright=(ichan*(ichip+1))&nbit_mask;
|
|
||||||
if (v!=vright) {
|
|
||||||
result++;
|
|
||||||
chipr++;
|
|
||||||
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
//printf("\n");
|
|
||||||
}
|
|
||||||
if (chipr)
|
|
||||||
printf("Test Counter module %d chip%d mux %d: %d errors\n", imod,ichip, ow,chipr);
|
|
||||||
}
|
|
||||||
free(values);
|
|
||||||
if (result)
|
|
||||||
printf("Test Counter module %d mux %d: %d errors\n", imod,ow,result);
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int testDataInOutMux(int imod, int ow, int num) {
|
int testDataInOutMux(int imod, int ow, int num) {
|
||||||
|
// reading via cPU doesnt work, so removed this functionality
|
||||||
int ichan, ichip, result=0, chipr=0, ind;
|
|
||||||
int vright,v;
|
|
||||||
int nbit_mask=0xffffff;
|
|
||||||
int *values, *v1;
|
|
||||||
|
|
||||||
printf("Testing data inout for module %d, mux %d, pattern 0x%x\n", imod, ow, num);
|
|
||||||
setExposureTime(0);
|
|
||||||
setFrames(1);
|
|
||||||
setTrains(1);
|
|
||||||
|
|
||||||
|
|
||||||
if (ow==2)
|
|
||||||
nbit_mask=0xffff;
|
|
||||||
else if (ow==3)
|
|
||||||
nbit_mask=0xff;
|
|
||||||
else if (ow==4)
|
|
||||||
nbit_mask=0xf;
|
|
||||||
else if (ow==5)
|
|
||||||
nbit_mask=0x1;
|
|
||||||
|
|
||||||
vright=num&nbit_mask;
|
|
||||||
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
//printf("Testin data in out\n");
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
initChannel(0,0,0,0,0,num,ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
initChipWithProbes(0, ow,0,ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
putout("0000000000000000",ALLMOD);
|
|
||||||
|
|
||||||
// Readout with SM
|
|
||||||
|
|
||||||
printf("mux %d\n",ow);
|
|
||||||
startReadOut();
|
|
||||||
usleep(100);
|
|
||||||
v1=(int*)(fifo_read_event());
|
|
||||||
if (v1)
|
|
||||||
values=(int*)(decode_data(v1));
|
|
||||||
else {
|
|
||||||
printf("no data found in fifos\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (ichip=0; ichip<NCHIP; ichip++) {
|
|
||||||
chipr=0;
|
|
||||||
for (ichan=0; ichan<NCHAN; ichan++) {
|
|
||||||
ind=ichan+(ichip+imod*NCHIP)*NCHAN;
|
|
||||||
v=values[ind];
|
|
||||||
if (v!=vright) {
|
|
||||||
result++;
|
|
||||||
chipr++;
|
|
||||||
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
//printf("\n");
|
|
||||||
}
|
|
||||||
if (chipr)
|
|
||||||
printf("Test DatInOut module %d chip %d mux %d: %d errors\n", imod,ichip, ow,chipr);
|
|
||||||
}
|
|
||||||
if (result)
|
|
||||||
printf("Test DatInOut module %d mux %d: %d errors\n", imod,ow,result);
|
|
||||||
free(values);
|
|
||||||
if (result)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "firmware_funcs.h"
|
#include "firmware_funcs.h"
|
||||||
#include "mcb_funcs.h"
|
#include "mcb_funcs.h"
|
||||||
#include "trimming_funcs.h"
|
|
||||||
#include "registers_g.h"
|
#include "registers_g.h"
|
||||||
#include "gitInfoGotthard.h"
|
#include "gitInfoGotthard.h"
|
||||||
#include "AD9257.h" // include "commonServerFunctions.h"
|
#include "AD9257.h" // include "commonServerFunctions.h"
|
||||||
@ -82,7 +81,6 @@ int init_detector( int b) {
|
|||||||
printf("Initializing Detector\n");
|
printf("Initializing Detector\n");
|
||||||
#endif
|
#endif
|
||||||
testFpga();
|
testFpga();
|
||||||
testRAM();
|
|
||||||
|
|
||||||
//gotthard specific
|
//gotthard specific
|
||||||
setPhaseShiftOnce();
|
setPhaseShiftOnce();
|
||||||
@ -710,9 +708,9 @@ int digital_test(int file_des) {
|
|||||||
case DETECTOR_FIRMWARE_TEST:
|
case DETECTOR_FIRMWARE_TEST:
|
||||||
retval=testFpga();
|
retval=testFpga();
|
||||||
break;
|
break;
|
||||||
case DETECTOR_MEMORY_TEST:
|
/*case DETECTOR_MEMORY_TEST:
|
||||||
ret=testRAM();
|
ret=testRAM();
|
||||||
break;
|
break;*/
|
||||||
case DETECTOR_BUS_TEST:
|
case DETECTOR_BUS_TEST:
|
||||||
retval=testBus();
|
retval=testBus();
|
||||||
break;
|
break;
|
||||||
@ -1919,93 +1917,44 @@ int get_run_status(int file_des) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int read_frame(int file_des) {
|
int read_frame(int file_des) {
|
||||||
|
dataret = FAIL;
|
||||||
|
strcpy(mess,"wait for read frame failed\n");
|
||||||
|
|
||||||
if (differentClients==1 && lockStatus==1) {
|
if (differentClients==1 && lockStatus==1) {
|
||||||
dataret=FAIL;
|
dataret=FAIL;
|
||||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
cprintf(RED,"%s\n",mess);
|
||||||
sendDataOnly(file_des,mess,sizeof(mess));
|
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
||||||
#ifdef VERBOSE
|
sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
printf("dataret %d\n",dataret);
|
return dataret;
|
||||||
#endif
|
}
|
||||||
return dataret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
#ifdef VIRTUAL
|
||||||
if (storeInRAM==0) {
|
dataret = FINISHED;
|
||||||
if ((dataretval=(char*)fifo_read_event())) {
|
strcpy(mess,"acquisition successfully finished\n");
|
||||||
dataret=OK;
|
#else
|
||||||
#ifdef VERYVERBOSE
|
waitForAcquisitionFinish();
|
||||||
printf("Sending ptr %x %d\n",(unsigned int)(dataretval), dataBytes);
|
|
||||||
|
// set return value and message
|
||||||
|
if(getFrames()>-2) {
|
||||||
|
dataret = FAIL;
|
||||||
|
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
||||||
|
cprintf(RED,"%s\n",mess);
|
||||||
|
} else {
|
||||||
|
dataret = FINISHED;
|
||||||
|
sprintf(mess,"acquisition successfully finished\n");
|
||||||
|
cprintf(GREEN,"%s",mess);
|
||||||
|
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
|
||||||
sendDataOnly(file_des,dataretval,dataBytes);
|
if (differentClients)
|
||||||
#ifdef VERBOSE
|
dataret=FORCE_UPDATE;
|
||||||
printf("sent %d bytes \n",dataBytes);
|
|
||||||
printf("dataret OK\n");
|
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
||||||
#endif
|
sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
return OK;
|
return dataret;
|
||||||
} else {
|
|
||||||
//might add delay????
|
|
||||||
if(getFrames()>-2) {
|
|
||||||
dataret=FAIL;
|
|
||||||
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
|
||||||
printf("%s\n",mess);
|
|
||||||
} else {
|
|
||||||
dataret=FINISHED;
|
|
||||||
sprintf(mess,"acquisition successfully finished\n");
|
|
||||||
printf("%s\n",mess);
|
|
||||||
}
|
|
||||||
#ifdef VERYVERBOSE
|
|
||||||
printf("%d %d %x %s\n",(int)(sizeof(mess)),(int)(strlen(mess)),(unsigned int)( mess),mess);
|
|
||||||
#endif
|
|
||||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
|
||||||
sendDataOnly(file_des,mess,sizeof(mess));
|
|
||||||
#ifdef VERYVERBOSE
|
|
||||||
printf("message sent %s\n",mess);
|
|
||||||
#endif
|
|
||||||
printf("dataret %d\n",dataret);
|
|
||||||
return dataret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nframes=0;
|
|
||||||
while(fifo_read_event()) {
|
|
||||||
nframes++;
|
|
||||||
}
|
|
||||||
dataretval=(char*)ram_values;
|
|
||||||
dataret=OK;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("sending data of %d frames\n",nframes);
|
|
||||||
#endif
|
|
||||||
for (iframes=0; iframes<nframes; iframes++) {
|
|
||||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
|
||||||
#ifdef VERYVERBOSE
|
|
||||||
printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes);
|
|
||||||
#endif
|
|
||||||
sendDataOnly(file_des,dataretval,dataBytes);
|
|
||||||
dataretval+=dataBytes;
|
|
||||||
}
|
|
||||||
if (getFrames()>-2) {
|
|
||||||
dataret=FAIL;
|
|
||||||
sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2));
|
|
||||||
printf("%s\n",mess);
|
|
||||||
} else {
|
|
||||||
dataret=FINISHED;
|
|
||||||
sprintf(mess,"acquisition successfully finished\n");
|
|
||||||
printf("%s\n",mess);
|
|
||||||
if (differentClients)
|
|
||||||
dataret=FORCE_UPDATE;
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Frames left %d\n",(int)(getFrames()));
|
|
||||||
#endif
|
|
||||||
sendDataOnly(file_des,&dataret,sizeof(dataret));
|
|
||||||
sendDataOnly(file_des,mess,sizeof(mess));
|
|
||||||
printf("dataret %d\n",dataret);
|
|
||||||
return dataret;
|
|
||||||
}
|
|
||||||
printf("dataret %d\n",dataret);
|
|
||||||
return dataret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2097,9 +2046,9 @@ int set_timer(int file_des) {
|
|||||||
printf(mess);
|
printf(mess);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
printf("setting timer %d to %lld ns\n",ind,tns);
|
printf("setting timer %d to %lld ns\n",ind,tns);
|
||||||
#endif
|
//#endif
|
||||||
if (ret==OK) {
|
if (ret==OK) {
|
||||||
|
|
||||||
if (differentClients==1 && lockStatus==1 && tns!=-1) {
|
if (differentClients==1 && lockStatus==1 && tns!=-1) {
|
||||||
@ -2150,10 +2099,6 @@ int set_timer(int file_des) {
|
|||||||
if (ret!=OK) {
|
if (ret!=OK) {
|
||||||
printf(mess);
|
printf(mess);
|
||||||
printf("set timer failed\n");
|
printf("set timer failed\n");
|
||||||
} else if (ind==FRAME_NUMBER) {
|
|
||||||
ret=allocateRAM();
|
|
||||||
if (ret!=OK)
|
|
||||||
sprintf(mess, "could not allocate RAM for %lld frames\n", tns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
@ -2294,12 +2239,6 @@ int set_dynamic_range(int file_des) {
|
|||||||
//if (dr>=0 && retval!=dr) ret=FAIL;
|
//if (dr>=0 && retval!=dr) ret=FAIL;
|
||||||
if (ret!=OK) {
|
if (ret!=OK) {
|
||||||
sprintf(mess,"set dynamic range failed\n");
|
sprintf(mess,"set dynamic range failed\n");
|
||||||
} else {
|
|
||||||
ret=allocateRAM();
|
|
||||||
if (ret!=OK)
|
|
||||||
sprintf(mess,"Could not allocate RAM for the dynamic range selected\n");
|
|
||||||
else if (differentClients)
|
|
||||||
ret=FORCE_UPDATE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
#include "sharedmemory.h"
|
|
||||||
|
|
||||||
struct statusdata *stdata;
|
|
||||||
|
|
||||||
int inism(int clsv) {
|
|
||||||
|
|
||||||
static int scansmid;
|
|
||||||
|
|
||||||
if (clsv==SMSV) {
|
|
||||||
if ( (scansmid=shmget(SMKEY,1024,IPC_CREAT | 0666 ))==-1 ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clsv==SMCL) {
|
|
||||||
if ( (scansmid=shmget(SMKEY,0,0) )==-1 ) {
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_status_sm(char *status) {
|
|
||||||
strcpy(stdata->status,status);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_stop_sm(int v) {
|
|
||||||
stdata->stop=v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_runnumber_sm(int v) {
|
|
||||||
stdata->runnumber=v;
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
#ifndef SM
|
|
||||||
#define SM
|
|
||||||
|
|
||||||
#include "sls_detector_defs.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>
|
|
||||||
|
|
||||||
|
|
||||||
#include <sys/shm.h>
|
|
||||||
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
/* key for shared memory */
|
|
||||||
#define SMKEY 10001
|
|
||||||
|
|
||||||
#define SMSV 1
|
|
||||||
#define SMCL 2
|
|
||||||
|
|
||||||
|
|
||||||
struct statusdata {
|
|
||||||
int runnumber;
|
|
||||||
int stop;
|
|
||||||
char status[20];
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
/* for shared memory */
|
|
||||||
|
|
||||||
int inism(int clsv);
|
|
||||||
void write_status_sm(char *status);
|
|
||||||
void write_stop_sm(int v);
|
|
||||||
void write_runnumber_sm(int v);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,749 +0,0 @@
|
|||||||
#ifndef PICASSOD
|
|
||||||
#include "server_defs.h"
|
|
||||||
#else
|
|
||||||
#include "picasso_defs.h"
|
|
||||||
#endif
|
|
||||||
#include "trimming_funcs.h"
|
|
||||||
#include "mcb_funcs.h"
|
|
||||||
#include "firmware_funcs.h"
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int nModX;
|
|
||||||
//extern int *values;
|
|
||||||
|
|
||||||
extern const int nChans;
|
|
||||||
extern const int nChips;
|
|
||||||
extern const int nDacs;
|
|
||||||
extern const int nAdcs;
|
|
||||||
|
|
||||||
|
|
||||||
int trim_fixed_settings(int countlim, int par2, int im)
|
|
||||||
{
|
|
||||||
|
|
||||||
int retval=OK;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Trimming with fixed settings\n");
|
|
||||||
#endif
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
return OK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (par2<=0)
|
|
||||||
retval=trim_with_level(countlim, im);
|
|
||||||
else
|
|
||||||
retval=trim_with_median(countlim,im);
|
|
||||||
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int trim_with_noise(int countlim, int nsigma, int im)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
int retval=OK, retval1=OK, retval2=OK;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Trimming using noise\n");
|
|
||||||
#endif
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
return OK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* threshold scan */
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("chosing vthresh and vtrim.....");
|
|
||||||
#endif
|
|
||||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("trimming with noise.....\n");
|
|
||||||
#endif
|
|
||||||
retval2=trim_with_level(countlim, im);
|
|
||||||
|
|
||||||
#ifdef DEBUGOUT
|
|
||||||
printf("done\n");
|
|
||||||
#endif
|
|
||||||
if (retval1==OK && retval2==OK)
|
|
||||||
retval=OK;
|
|
||||||
else
|
|
||||||
retval=FAIL;
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int trim_with_beam(int countlim, int nsigma, int im) //rpc
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
int retval=OK, retval1=OK, retval2=OK;
|
|
||||||
|
|
||||||
printf("Trimming using beam\n");
|
|
||||||
//return OK;
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
printf("Trimming using beam\n");
|
|
||||||
return OK;
|
|
||||||
#endif
|
|
||||||
/* threshold scan */
|
|
||||||
#ifdef DEBUGOUT
|
|
||||||
printf("chosing vthresh and vtrim.....");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
|
|
||||||
retval2=trim_with_median(TRIM_DR, im);
|
|
||||||
|
|
||||||
#ifdef DEBUGOUT
|
|
||||||
printf("done\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (retval1==OK && retval2==OK)
|
|
||||||
retval=OK;
|
|
||||||
else
|
|
||||||
retval=FAIL;
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int trim_improve(int maxit, int par2, int im) //rpc
|
|
||||||
{
|
|
||||||
|
|
||||||
int retval=OK, retval1=OK, retval2=OK;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Improve the trimming\n");
|
|
||||||
#endif
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
return OK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (par2!=0 && im==ALLMOD)
|
|
||||||
retval1=choose_vthresh();
|
|
||||||
|
|
||||||
retval2=trim_with_median(2*maxit+1, im);
|
|
||||||
#ifdef DEBUGOUT
|
|
||||||
printf("done\n");
|
|
||||||
#endif
|
|
||||||
if (retval1==OK && retval2==OK)
|
|
||||||
retval=OK;
|
|
||||||
else
|
|
||||||
retval=FAIL;
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int calcthr_from_vcal(int vcal) {
|
|
||||||
int thrmin;
|
|
||||||
//thrmin=140+3*vcal/5;
|
|
||||||
thrmin=180+3*vcal/5;
|
|
||||||
return thrmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
int calccal_from_vthr(int vthr) {
|
|
||||||
int vcal;
|
|
||||||
vcal=5*(vthr-140)/3;
|
|
||||||
return vcal;
|
|
||||||
}
|
|
||||||
|
|
||||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
|
||||||
int retval=OK;
|
|
||||||
#ifdef MCB_FUNCS
|
|
||||||
int modma, modmi, nm;
|
|
||||||
int thr, thrstep=5, nthr=31;
|
|
||||||
|
|
||||||
int *fifodata;
|
|
||||||
|
|
||||||
double vthreshmean, vthreshSTDev;
|
|
||||||
int *thrmi, *thrma;
|
|
||||||
double c;
|
|
||||||
//double b=BVTRIM;
|
|
||||||
//double a=AVTRIM;
|
|
||||||
int *trim;
|
|
||||||
int ich, imod, ichan;
|
|
||||||
int nvalid=0;
|
|
||||||
u_int32_t *scan;
|
|
||||||
int ithr;
|
|
||||||
sls_detector_channel myChan;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setFrames(1);
|
|
||||||
// setNMod(getNModBoard());
|
|
||||||
|
|
||||||
if (im==ALLMOD){
|
|
||||||
modmi=0;
|
|
||||||
modma=nModX;
|
|
||||||
} else {
|
|
||||||
modmi=im;
|
|
||||||
modma=im+1;
|
|
||||||
}
|
|
||||||
nm=modma-modmi;
|
|
||||||
|
|
||||||
trim=malloc(sizeof(int)*nChans*nChips*nModX);
|
|
||||||
thrmi=malloc(sizeof(int)*nModX);
|
|
||||||
thrma=malloc(sizeof(int)*nModX);
|
|
||||||
|
|
||||||
|
|
||||||
for (ich=0; ich<nChans*nChips*nm; ich++)
|
|
||||||
trim[ich]=-1;
|
|
||||||
/*
|
|
||||||
setCSregister(im);
|
|
||||||
setSSregister(im);
|
|
||||||
initChannel(0,0,0,1,0,0,im);
|
|
||||||
counterClear(im);
|
|
||||||
clearSSregister(im);
|
|
||||||
usleep(500);
|
|
||||||
*/
|
|
||||||
myChan.chan=-1;
|
|
||||||
myChan.chip=-1;
|
|
||||||
myChan.module=ALLMOD;
|
|
||||||
myChan.reg=COMPARATOR_ENABLE;
|
|
||||||
initChannelbyNumber(myChan);
|
|
||||||
|
|
||||||
|
|
||||||
for (ithr=0; ithr<nthr; ithr++) {
|
|
||||||
fifoReset();
|
|
||||||
/* scanning threshold */
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
//commented out by dhanya thr=getDACbyIndexDACU(VTHRESH,imod);
|
|
||||||
if (ithr==0) {
|
|
||||||
thrmi[imod]=thr;
|
|
||||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
|
||||||
} else
|
|
||||||
;//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
initChannel(0,0,0,1,0,0,im);
|
|
||||||
setDynamicRange(32);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
fifodata=(int*)fifo_read_event();
|
|
||||||
scan=decode_data(fifodata);
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
|
||||||
ich=imod*nChips*nChans+ichan;
|
|
||||||
if (scan[ich]>countlim && trim[ich]==-1) {
|
|
||||||
//commented out by dhanya trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
|
|
||||||
#ifdef VERBOSE
|
|
||||||
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
/* else {
|
|
||||||
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
|
|
||||||
}*/
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(scan);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
vthreshmean=0;
|
|
||||||
vthreshSTDev=0;
|
|
||||||
nvalid=0;
|
|
||||||
//commented out by dhanya thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
|
|
||||||
|
|
||||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
|
||||||
ich=imod*nChans*nChips+ichan;
|
|
||||||
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
|
|
||||||
vthreshmean=vthreshmean+trim[ich];
|
|
||||||
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
|
|
||||||
nvalid++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nvalid>0) {
|
|
||||||
vthreshmean=vthreshmean/nvalid;
|
|
||||||
//commented out by dhanya vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean);
|
|
||||||
} else {
|
|
||||||
vthreshmean=thrmi[imod];
|
|
||||||
vthreshSTDev=nthr*thrstep;
|
|
||||||
printf("No valid channel for module %d\n",imod);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUGOUT
|
|
||||||
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
|
|
||||||
#endif
|
|
||||||
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
|
|
||||||
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
|
|
||||||
if (thr<0 || thr>(DAC_DR-1)) {
|
|
||||||
thr=thrmi[imod]/2;
|
|
||||||
printf("Can't find correct threshold for module %d\n",imod);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("vthresh=%d \n",thr);
|
|
||||||
#endif
|
|
||||||
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
|
|
||||||
//commented out by dhanya thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a));
|
|
||||||
if (thr<500 || thr>(DAC_DR-1)) {
|
|
||||||
thr=750;
|
|
||||||
printf("Can't find correct trimbit size for module %d\n",imod);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod);
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("vtrim=%d \n",thr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
free(trim);
|
|
||||||
free(thrmi);
|
|
||||||
free(thrma);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int trim_with_level(int countlim, int im) {
|
|
||||||
int ich, itrim, ichan, ichip, imod;
|
|
||||||
u_int32_t *scan;
|
|
||||||
int *inttrim;
|
|
||||||
int modma, modmi, nm;
|
|
||||||
int retval=OK;
|
|
||||||
int *fifodata;
|
|
||||||
sls_detector_channel myChan;
|
|
||||||
printf("trimming module number %d", im);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MCB_FUNCS
|
|
||||||
setFrames(1);
|
|
||||||
// setNMod(getNModBoard());
|
|
||||||
|
|
||||||
if (im==ALLMOD){
|
|
||||||
modmi=0;
|
|
||||||
modma=nModX;
|
|
||||||
} else {
|
|
||||||
modmi=im;
|
|
||||||
modma=im+1;
|
|
||||||
}
|
|
||||||
nm=modma-modmi;
|
|
||||||
|
|
||||||
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
|
|
||||||
printf("countlim=%d\n",countlim);
|
|
||||||
for (ich=0; ich<nChans*nChips*nModX; ich++)
|
|
||||||
inttrim[ich]=-1;
|
|
||||||
|
|
||||||
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
|
|
||||||
fifoReset();
|
|
||||||
printf("Trimbit %d\n",itrim);
|
|
||||||
myChan.chan=-1;
|
|
||||||
myChan.chip=-1;
|
|
||||||
myChan.module=ALLMOD;
|
|
||||||
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
|
|
||||||
initChannelbyNumber(myChan);
|
|
||||||
|
|
||||||
/*
|
|
||||||
setCSregister(im);
|
|
||||||
setSSregister(im);
|
|
||||||
initChannel(itrim,0,0,1,0,0,ALLMOD);
|
|
||||||
setDynamicRange(32);
|
|
||||||
*/
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
|
|
||||||
fifodata=(int*)fifo_read_event();
|
|
||||||
scan=decode_data(fifodata);
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
|
||||||
ich=ichan+imod*nChans*nChips;
|
|
||||||
if (inttrim[ich]==-1) {
|
|
||||||
if (scan[ich]>countlim){
|
|
||||||
inttrim[ich]=itrim;
|
|
||||||
if (scan[ich]>2*countlim && itrim>0) {
|
|
||||||
//if (scan[ich]>2*countlim || itrim==0) {
|
|
||||||
inttrim[ich]=itrim-1;
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
/* else
|
|
||||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(scan);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
clearCSregister(imod);
|
|
||||||
firstChip(im);
|
|
||||||
for (ichip=0; ichip<nChips; ichip++) {
|
|
||||||
clearSSregister(imod);
|
|
||||||
for (ichan=0; ichan<nChans; ichan++) {
|
|
||||||
nextStrip(imod);
|
|
||||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
|
||||||
if (*(inttrim+ich)==-1) {
|
|
||||||
*(inttrim+ich)=TRIM_DR;
|
|
||||||
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
|
||||||
// else
|
|
||||||
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
|
||||||
#endif
|
|
||||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
|
||||||
}
|
|
||||||
nextChip(imod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(inttrim);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
|
||||||
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
|
|
||||||
|
|
||||||
|
|
||||||
int kth_smallest(int *a, int n, int k)
|
|
||||||
{
|
|
||||||
register int i,j,l,m ;
|
|
||||||
register double x ;
|
|
||||||
|
|
||||||
l=0 ; m=n-1 ;
|
|
||||||
while (l<m) {
|
|
||||||
x=a[k] ;
|
|
||||||
i=l ;
|
|
||||||
j=m ;
|
|
||||||
do {
|
|
||||||
while (a[i]<x) i++ ;
|
|
||||||
while (x<a[j]) j-- ;
|
|
||||||
if (i<=j) {
|
|
||||||
ELEM_SWAP(a[i],a[j]) ;
|
|
||||||
i++ ; j-- ;
|
|
||||||
}
|
|
||||||
} while (i<=j) ;
|
|
||||||
if (j<k) l=i ;
|
|
||||||
if (k<i) m=j ;
|
|
||||||
}
|
|
||||||
return a[k] ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ave(int *a, int n)
|
|
||||||
{
|
|
||||||
int av=0,i;
|
|
||||||
for (i=0; i<n; i++)
|
|
||||||
av=av+((double)*(a+i))/((double)n);
|
|
||||||
return av;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int choose_vthresh() {
|
|
||||||
|
|
||||||
int retval=OK;
|
|
||||||
#ifdef MCB_FUNCS
|
|
||||||
int imod, ichan;
|
|
||||||
u_int32_t *scan, *scan1;
|
|
||||||
int olddiff[nModX], direction[nModX];
|
|
||||||
int med[nModX], med1[nModX], diff, media;
|
|
||||||
int change_flag=1;
|
|
||||||
int iteration=0;
|
|
||||||
int maxiterations=10;
|
|
||||||
int vthreshmean=0;
|
|
||||||
int vthresh;
|
|
||||||
int im=ALLMOD;
|
|
||||||
int modma, modmi, nm;
|
|
||||||
int *fifodata;
|
|
||||||
|
|
||||||
setFrames(1);
|
|
||||||
// setNMod(getNModBoard());
|
|
||||||
|
|
||||||
if (im==ALLMOD){
|
|
||||||
modmi=0;
|
|
||||||
modma=nModX;
|
|
||||||
} else {
|
|
||||||
modmi=im;
|
|
||||||
modma=im+1;
|
|
||||||
}
|
|
||||||
nm=modma-modmi;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setDynamicRange(32);
|
|
||||||
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
//printf(".");
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
|
|
||||||
fifodata=(int*)fifo_read_event();
|
|
||||||
scan=decode_data(fifodata);
|
|
||||||
//
|
|
||||||
scan1=decode_data(fifodata);
|
|
||||||
|
|
||||||
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
//
|
|
||||||
med[imod]=(int)median((int*)scan1+imod*nChans*nChips,nChans*nChips);
|
|
||||||
med1[imod]=med[imod];
|
|
||||||
//commented out by dhanya vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
|
||||||
olddiff[imod]=0xffffff;
|
|
||||||
direction[imod]=0;
|
|
||||||
printf("Median of module %d=%d\n",imod,med[imod]);
|
|
||||||
}
|
|
||||||
vthreshmean=vthreshmean/nm;
|
|
||||||
//media=median(scan,nChans*nChips*nModX);
|
|
||||||
//printf("Median overall=%d\n",media);
|
|
||||||
media=median(med1+modmi,nm);
|
|
||||||
printf("Median of modules=%d\n",media);
|
|
||||||
free(scan);
|
|
||||||
free(scan1);
|
|
||||||
|
|
||||||
|
|
||||||
while(change_flag && iteration<maxiterations) {
|
|
||||||
|
|
||||||
setDynamicRange(32);
|
|
||||||
fifoReset();
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
|
|
||||||
fifodata=(int*)fifo_read_event();
|
|
||||||
scan=decode_data(fifodata);
|
|
||||||
//
|
|
||||||
scan1=decode_data(fifodata);
|
|
||||||
|
|
||||||
change_flag=0;
|
|
||||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
|
||||||
for (ichan=modmi; ichan<modma; ichan++) {
|
|
||||||
med[ichan]=(int)median((int*)scan1+ichan*nChans*nChips,nChans*nChips);
|
|
||||||
med1[imod]=med[imod];
|
|
||||||
media=median(med1+modmi,nm);
|
|
||||||
|
|
||||||
diff=med[ichan]-media;
|
|
||||||
if (direction[ichan]==0) {
|
|
||||||
if (diff>0)
|
|
||||||
direction[ichan]=1;
|
|
||||||
else
|
|
||||||
direction[ichan]=-1;
|
|
||||||
}
|
|
||||||
//commented out by dhanya vthresh=getDACbyIndexDACU(VTHRESH,imod);
|
|
||||||
if ( direction[ichan]!=-3) {
|
|
||||||
if (abs(diff)>abs(olddiff[ichan])) {
|
|
||||||
vthresh=vthresh-direction[ichan];
|
|
||||||
if (vthresh>(DAC_DR-1)) {
|
|
||||||
vthresh=(DAC_DR-1);
|
|
||||||
printf("can't equalize threshold for module %d\n", ichan);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
if (vthresh<0) {
|
|
||||||
vthresh=0;
|
|
||||||
printf("can't equalize threshold for module %d\n", ichan);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
direction[ichan]=-3;
|
|
||||||
} else {
|
|
||||||
vthresh=vthresh+direction[ichan];
|
|
||||||
olddiff[ichan]=diff;
|
|
||||||
change_flag=1;
|
|
||||||
}
|
|
||||||
//commented out by dhanya initDACbyIndex(VTHRESH,vthresh, ichan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iteration++;
|
|
||||||
free(scan);
|
|
||||||
free(scan1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int trim_with_median(int stop, int im) {
|
|
||||||
|
|
||||||
|
|
||||||
int retval=OK;
|
|
||||||
|
|
||||||
#ifdef MCB_FUNCS
|
|
||||||
int ichan, imod, ichip, ich;
|
|
||||||
u_int32_t *scan, *scan1;
|
|
||||||
int *olddiff, *direction;
|
|
||||||
int med, diff;
|
|
||||||
int change_flag=1;
|
|
||||||
int iteration=0;
|
|
||||||
int me[nModX], me1[nModX];
|
|
||||||
int modma, modmi, nm;
|
|
||||||
int trim;
|
|
||||||
int *fifodata;
|
|
||||||
|
|
||||||
setFrames(1);
|
|
||||||
// setNMod(getNModBoard());
|
|
||||||
|
|
||||||
if (im==ALLMOD){
|
|
||||||
modmi=0;
|
|
||||||
modma=nModX;
|
|
||||||
} else {
|
|
||||||
modmi=im;
|
|
||||||
modma=im+1;
|
|
||||||
}
|
|
||||||
nm=modma-modmi;
|
|
||||||
|
|
||||||
olddiff=malloc(4*nModX*nChips*nChans);
|
|
||||||
direction=malloc(4*nModX*nChips*nChans);
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
for (ichip=0; ichip<nChips; ichip++) {
|
|
||||||
for (ich=0; ich<nChans; ich++) {
|
|
||||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
|
||||||
direction[ichan]=0;
|
|
||||||
olddiff[ichan]=0x0fffffff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/********
|
|
||||||
fifoReset();
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
scan=decode_data(fifo_read_event());
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
|
||||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
|
||||||
}
|
|
||||||
med=median(me,nm);
|
|
||||||
printf("median is %d\n",med);
|
|
||||||
free(scan);
|
|
||||||
**************/
|
|
||||||
while(change_flag && iteration<stop) {
|
|
||||||
|
|
||||||
setDynamicRange(32);
|
|
||||||
fifoReset();
|
|
||||||
setCSregister(ALLMOD);
|
|
||||||
setSSregister(ALLMOD);
|
|
||||||
counterClear(ALLMOD);
|
|
||||||
clearSSregister(ALLMOD);
|
|
||||||
usleep(500);
|
|
||||||
startStateMachine();
|
|
||||||
while (runBusy()) {
|
|
||||||
}
|
|
||||||
usleep(500);
|
|
||||||
fifodata=(int*)fifo_read_event();
|
|
||||||
scan=decode_data(fifodata);
|
|
||||||
scan1=decode_data(fifodata);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********* calculates median every time ***********/
|
|
||||||
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
me[imod]=median((int*)scan1+imod*nChans*nChips,nChans*nChips);
|
|
||||||
me1[imod]=me[imod];
|
|
||||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
|
||||||
}
|
|
||||||
med=median(me1,nm);
|
|
||||||
printf("median is %d\n",med);
|
|
||||||
|
|
||||||
change_flag=0;
|
|
||||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
|
||||||
for (imod=modmi; imod<modma; imod++) {
|
|
||||||
for (ichip=0; ichip<nChips; ichip++) {
|
|
||||||
selChip(ichip,imod);
|
|
||||||
clearSSregister(imod);
|
|
||||||
for (ich=0; ich<nChans; ich++) {
|
|
||||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
|
||||||
nextStrip(imod);
|
|
||||||
diff=scan[ichan]-me[imod];
|
|
||||||
if (direction[ichan]==0) {
|
|
||||||
if (diff>0) {
|
|
||||||
direction[ichan]=1;
|
|
||||||
} else {
|
|
||||||
direction[ichan]=-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( direction[ichan]!=-3) {
|
|
||||||
if (abs(diff)>abs(olddiff[ichan])) {
|
|
||||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
|
||||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
|
||||||
direction[ichan]=-3;
|
|
||||||
} else {
|
|
||||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
|
||||||
olddiff[ichan]=diff;
|
|
||||||
change_flag=1;
|
|
||||||
}
|
|
||||||
if (trim>TRIM_DR) {
|
|
||||||
trim=63;
|
|
||||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
if (trim<0) {
|
|
||||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
|
||||||
trim=0;
|
|
||||||
retval=FAIL;
|
|
||||||
}
|
|
||||||
initChannel(trim,0,0,1,0,0,imod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iteration++;
|
|
||||||
free(scan);
|
|
||||||
free(scan1);
|
|
||||||
}
|
|
||||||
free(olddiff);
|
|
||||||
free(direction);
|
|
||||||
#endif
|
|
||||||
return retval;
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#ifndef TRIMMING_FUNCS_H
|
|
||||||
#define TRIMMING_FUNCS_H
|
|
||||||
|
|
||||||
#include "sls_detector_defs.h"
|
|
||||||
|
|
||||||
int trim_fixed_settings(int countlim, int par2, int imod);
|
|
||||||
int trim_with_noise(int countlim, int nsigma, int imod);
|
|
||||||
int trim_with_beam(int countlim, int nsigma, int imod);
|
|
||||||
int trim_improve(int maxit, int par2, int imod);
|
|
||||||
int calcthr_from_vcal(int vcal);
|
|
||||||
int calccal_from_vthr(int vthr);
|
|
||||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
|
|
||||||
|
|
||||||
int choose_vthresh();
|
|
||||||
int trim_with_level(int countlim, int imod);
|
|
||||||
int trim_with_median(int stop, int imod);
|
|
||||||
int calcthr_from_vcal(int vcal);
|
|
||||||
int calccal_from_vthr(int vthr);
|
|
||||||
|
|
||||||
#endif
|
|
@ -2458,7 +2458,7 @@ int* multiSlsDetector::getDataFromDetector() {
|
|||||||
int nodatadet = -1;
|
int nodatadet = -1;
|
||||||
int nodatadetectortype = false;
|
int nodatadetectortype = false;
|
||||||
detectorType types = getDetectorsType();
|
detectorType types = getDetectorsType();
|
||||||
if (types == EIGER || types == JUNGFRAU) {
|
if (types == EIGER || types == JUNGFRAU || GOTTHARD || PROPIX) {
|
||||||
nodatadetectortype = true;
|
nodatadetectortype = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5082,7 +5082,7 @@ void multiSlsDetector::readFrameFromReceiver() {
|
|||||||
coordX = doc["column"].GetUint();
|
coordX = doc["column"].GetUint();
|
||||||
if (eiger)
|
if (eiger)
|
||||||
coordY = (nY - 1) - coordY;
|
coordY = (nY - 1) - coordY;
|
||||||
//cout << "X:" << doc["row"].GetUint() <<" Y:"<<doc["column"].GetUint();
|
//cout << "X:" << doc["row"].GetUint() <<" Y:"<<doc["column"].GetUint();
|
||||||
flippedDataX = doc["flippedDataX"].GetUint();
|
flippedDataX = doc["flippedDataX"].GetUint();
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cprintf(BLUE, "(Debug) Header Info:\n"
|
cprintf(BLUE, "(Debug) Header Info:\n"
|
||||||
|
@ -3808,7 +3808,7 @@ int* slsDetector::getDataFromDetector(int *retval) {
|
|||||||
|
|
||||||
int nodatadetectortype = false;
|
int nodatadetectortype = false;
|
||||||
detectorType types = getDetectorsType();
|
detectorType types = getDetectorsType();
|
||||||
if(types == EIGER || types == JUNGFRAU){
|
if(types == EIGER || types == JUNGFRAU || GOTTHARD || PROPIX){
|
||||||
nodatadetectortype = true;
|
nodatadetectortype = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,13 +442,8 @@ void UDPStandardImplementation::setDetectorPositionId(const int i){
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||||
uint16_t row = 0, col = 0;
|
uint16_t row = 0, col = 0;
|
||||||
if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) {
|
row = detID % numDet[1]; // row
|
||||||
row = detID % numDet[1]; // row
|
col = (detID / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + i; // col for horiz. udp ports
|
||||||
col = (detID / numDet[1]) * ((myDetectorType == EIGER) ? 2 : 1) + i; // col for horiz. udp ports
|
|
||||||
}
|
|
||||||
// calculate x in 1d
|
|
||||||
else
|
|
||||||
row = detID * numThreads + i;
|
|
||||||
listener[i]->SetHardCodedPosition(row, col);
|
listener[i]->SetHardCodedPosition(row, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user