mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
set starting frame number of next acquisition for both jungfrau and e… (#27)
* set starting frame number of next acquisition for both jungfrau and eiger. firmware has not implemented a get, so workaround. tests included. frame number 0 not allowed due to Eiger. Eiger max frame is 48 bit, while jungfrau is 64 bit * made argument of setstartingframenumber const
This commit is contained in:
@ -36,6 +36,7 @@ int Beb_activated = 1;
|
||||
uint32_t Beb_detid = 0;
|
||||
int Beb_top =0;
|
||||
|
||||
uint64_t Beb_deactivatedStartFrameNumber = 0;
|
||||
|
||||
|
||||
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num) {
|
||||
@ -409,6 +410,10 @@ int Beb_Activate(int enable) {
|
||||
}
|
||||
|
||||
|
||||
int Beb_GetActivate() {
|
||||
return Beb_activated;
|
||||
}
|
||||
|
||||
int Beb_Set32bitOverflow(int val) {
|
||||
if (!Beb_activated)
|
||||
return val;
|
||||
@ -1262,6 +1267,62 @@ int Beb_SetDetectorPosition(int pos[]) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Beb_SetStartingFrameNumber(uint64_t value) {
|
||||
if (!Beb_activated) {
|
||||
Beb_deactivatedStartFrameNumber = value;
|
||||
return OK;
|
||||
}
|
||||
FILE_LOG(logINFO, ("Setting start frame number: %llu\n", (long long unsigned int)value));
|
||||
|
||||
u_int32_t* csp0base = 0;
|
||||
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
|
||||
if (fd < 0) {
|
||||
FILE_LOG(logERROR, ("Set Start Frame Number FAIL\n"));
|
||||
return FAIL;
|
||||
} else {
|
||||
// since the read is not implemented in firmware yet
|
||||
Beb_deactivatedStartFrameNumber = value;
|
||||
|
||||
// decrement for firmware
|
||||
uint64_t valueInFirmware = value - 1;
|
||||
Beb_Write32(csp0base, UDP_HEADER_FRAME_NUMBER_LSB_OFST, valueInFirmware & (0xffffffff));
|
||||
Beb_Write32(csp0base, UDP_HEADER_FRAME_NUMBER_MSB_OFST, (valueInFirmware >> 32) & (0xffffffff));
|
||||
Beb_close(fd,csp0base);
|
||||
}
|
||||
|
||||
uint64_t retval = -1;
|
||||
if ((Beb_GetStartingFrameNumber(&retval) == OK) && (retval == value)) {
|
||||
FILE_LOG(logINFO, ("Going to reset Frame Number\n"));
|
||||
Beb_ResetFrameNumber();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Beb_GetStartingFrameNumber(uint64_t* retval) {
|
||||
if (!Beb_activated) {
|
||||
*retval = Beb_deactivatedStartFrameNumber;
|
||||
return OK;
|
||||
}
|
||||
FILE_LOG(logDEBUG1, ("Getting start frame number\n"));
|
||||
|
||||
// since it is not implemented in firmware yet
|
||||
*retval = Beb_deactivatedStartFrameNumber;
|
||||
/*
|
||||
u_int32_t* csp0base = 0;
|
||||
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
|
||||
if (fd < 0) {
|
||||
FILE_LOG(logERROR, ("Set Start Frame Number FAIL\n"));
|
||||
return FAIL;
|
||||
} else {
|
||||
*retval = Beb_Read32(csp0base, UDP_HEADER_FRAME_NUMBER_MSB_OFST);
|
||||
uint32_t lretval = Beb_Read32(csp0base, UDP_HEADER_FRAME_NUMBER_MSB_OFST);
|
||||
*retval = (*retval << 32) | lretval;
|
||||
Beb_close(fd,csp0base);
|
||||
}
|
||||
*/
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
uint16_t Beb_swap_uint16( uint16_t val) {
|
||||
return (val << 8) | (val >> 8 );
|
||||
|
@ -39,6 +39,7 @@ void Beb_EndofDataSend(int tengiga);
|
||||
int Beb_SetMasterViaSoftware();
|
||||
int Beb_SetSlaveViaSoftware();
|
||||
int Beb_Activate(int enable);
|
||||
int Beb_GetActivate();
|
||||
int Beb_Set32bitOverflow(int val);
|
||||
int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val);
|
||||
int Beb_ResetToHardwareSettings();
|
||||
@ -74,6 +75,8 @@ int Beb_GetBebFPGATemp();
|
||||
|
||||
void Beb_SetDetectorNumber(uint32_t detid);
|
||||
int Beb_SetDetectorPosition(int pos[]);
|
||||
int Beb_SetStartingFrameNumber(uint64_t value);
|
||||
int Beb_GetStartingFrameNumber(uint64_t* retval);
|
||||
|
||||
uint16_t Beb_swap_uint16( uint16_t val);
|
||||
int Beb_open(u_int32_t** csp0base, u_int32_t offset);
|
||||
|
@ -202,8 +202,9 @@
|
||||
#define UDP_HEADER_Y_OFST (16)
|
||||
#define UDP_HEADER_Y_MSK (0xFFFF << UDP_HEADER_Y_OFST)
|
||||
|
||||
|
||||
|
||||
// udp header (frame number)
|
||||
#define UDP_HEADER_FRAME_NUMBER_LSB_OFST (0x0140)
|
||||
#define UDP_HEADER_FRAME_NUMBER_MSB_OFST (0x0160)
|
||||
|
||||
|
||||
|
||||
|
@ -85,6 +85,7 @@ int eiger_virtual_status=0;
|
||||
int eiger_virtual_activate=1;
|
||||
pthread_t eiger_virtual_tid;
|
||||
int eiger_virtual_stop = 0;
|
||||
uint64_t eiger_virtual_startingframenumber = 0;
|
||||
#endif
|
||||
|
||||
|
||||
@ -444,6 +445,7 @@ void setupDetector() {
|
||||
setSpeed(CLOCK_DIVIDER, DEFAULT_CLK_SPEED);//clk_devider,half speed
|
||||
setIODelay(DEFAULT_IO_DELAY);
|
||||
setTiming(DEFAULT_TIMING_MODE);
|
||||
setStartingFrameNumber(DEFAULT_STARTING_FRAME_NUMBER);
|
||||
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
|
||||
setRateCorrection(DEFAULT_RATE_CORRECTION);
|
||||
int enable[2] = {DEFAULT_EXT_GATING_ENABLE, DEFAULT_EXT_GATING_POLARITY};
|
||||
@ -658,6 +660,24 @@ enum readOutFlags setReadOutFlags(enum readOutFlags val) {
|
||||
|
||||
/* parameters - timer */
|
||||
|
||||
int setStartingFrameNumber(uint64_t value) {
|
||||
#ifdef VIRTUAL
|
||||
eiger_virtual_startingframenumber = value;
|
||||
return OK;
|
||||
#else
|
||||
return Beb_SetStartingFrameNumber(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
int getStartingFrameNumber(uint64_t* retval) {
|
||||
#ifdef VIRTUAL
|
||||
*retval = eiger_virtual_startingframenumber;
|
||||
return OK;
|
||||
#else
|
||||
return Beb_GetStartingFrameNumber(retval);
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val) {
|
||||
#ifndef VIRTUAL
|
||||
int64_t subdeadtime = 0;
|
||||
@ -1609,8 +1629,6 @@ int prepareAcquisition() {
|
||||
#ifndef VIRTUAL
|
||||
FILE_LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()));
|
||||
Feb_Control_PrepareForAcquisition();
|
||||
FILE_LOG(logINFO, ("Going to reset Frame Number\n"));
|
||||
Beb_ResetFrameNumber();
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
|
@ -51,6 +51,7 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE};
|
||||
|
||||
/** Default Parameters */
|
||||
#define DEFAULT_NUM_FRAMES (1)
|
||||
#define DEFAULT_STARTING_FRAME_NUMBER (1)
|
||||
#define DEFAULT_NUM_CYCLES (1)
|
||||
#define DEFAULT_EXPTIME (1E9) //ns
|
||||
#define DEFAULT_PERIOD (1E9) //ns
|
||||
@ -74,6 +75,8 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE};
|
||||
#define DEFAULT_TEST_MODE (0)
|
||||
#define DEFAULT_HIGH_VOLTAGE (0)
|
||||
|
||||
#define UDP_HEADER_MAX_FRAME_VALUE (0xFFFFFFFFFFFF)
|
||||
|
||||
#define DAC_MIN_MV (0)
|
||||
#define DAC_MAX_MV (2048)
|
||||
#define LTC2620_MIN_VAL (0) // including LTC defines instead of LTC262.h (includes bit banging and blackfin read and write)
|
||||
|
@ -388,6 +388,10 @@
|
||||
#define SET_EXPTIME_LSB_REG (0x68 << MEM_MAP_SHIFT)
|
||||
#define SET_EXPTIME_MSB_REG (0x69 << MEM_MAP_SHIFT)
|
||||
|
||||
/* Frame number 64 bit register */
|
||||
#define FRAME_NUMBER_LSB_REG (0x6A << MEM_MAP_SHIFT)
|
||||
#define FRAME_NUMBER_MSB_REG (0x6B << MEM_MAP_SHIFT)
|
||||
|
||||
/* Trigger Delay 32 bit register */
|
||||
#define SET_TRIGGER_DELAY_LSB_REG (0x70 << MEM_MAP_SHIFT)
|
||||
#define SET_TRIGGER_DELAY_MSB_REG (0x71 << MEM_MAP_SHIFT)
|
||||
|
@ -441,6 +441,7 @@ void setupDetector() {
|
||||
selectStoragecellStart(DEFAULT_STRG_CLL_STRT);
|
||||
/*setClockDivider(HALF_SPEED); depends if all the previous stuff works*/
|
||||
setTiming(DEFAULT_TIMING_MODE);
|
||||
setStartingFrameNumber(DEFAULT_STARTING_FRAME_NUMBER);
|
||||
|
||||
|
||||
// temp threshold and reset event
|
||||
@ -555,6 +556,20 @@ int selectStoragecellStart(int pos) {
|
||||
return ((bus_r(DAQ_REG) & DAQ_STRG_CELL_SLCT_MSK) >> DAQ_STRG_CELL_SLCT_OFST);
|
||||
}
|
||||
|
||||
int setStartingFrameNumber(uint64_t value) {
|
||||
FILE_LOG(logINFO, ("Setting starting frame number: %llu\n",(long long unsigned int)value));
|
||||
// decrement is for firmware
|
||||
setU64BitReg(value - 1, FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
// need to set it twice for the firmware to catch
|
||||
setU64BitReg(value - 1, FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getStartingFrameNumber(uint64_t* retval) {
|
||||
// increment is for firmware
|
||||
*retval = (getU64BitReg(FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG) + 1);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val) {
|
||||
|
@ -63,6 +63,7 @@ enum NETWORKINDEX { TXN_FRAME, FLOWCTRL_10G };
|
||||
|
||||
/** Default Parameters */
|
||||
#define DEFAULT_NUM_FRAMES (100*1000*1000)
|
||||
#define DEFAULT_STARTING_FRAME_NUMBER (1)
|
||||
#define DEFAULT_NUM_CYCLES (1)
|
||||
#define DEFAULT_EXPTIME (10*1000) //ns
|
||||
#define DEFAULT_PERIOD (2*1000*1000) //ns
|
||||
|
@ -97,6 +97,29 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read unsigned 64 bit from a 64 bit register
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
* @returns unsigned 64 bit data read
|
||||
*/
|
||||
uint64_t getU64BitReg(int aLSB, int aMSB){
|
||||
uint64_t retval = bus_r(aMSB);
|
||||
retval = (retval << 32) | bus_r(aLSB);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write unsigned 64 bit into a 64 bit register
|
||||
* @param value unsigned 64 bit data
|
||||
* @param aLSB LSB offset address
|
||||
* @param aMSB MSB offset address
|
||||
*/
|
||||
void setU64BitReg(uint64_t value, int aLSB, int aMSB){
|
||||
bus_w(aLSB, value & (0xffffffff));
|
||||
bus_w(aMSB, (value >> 32) & (0xffffffff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a 32 bit register (literal register value provided by client)
|
||||
* @param offset address offset
|
||||
|
@ -139,6 +139,10 @@ enum readOutFlags setReadOutFlags(enum readOutFlags val);
|
||||
#ifdef JUNGFRAUD
|
||||
int selectStoragecellStart(int pos);
|
||||
#endif
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
int setStartingFrameNumber(uint64_t value);
|
||||
int getStartingFrameNumber(uint64_t* value);
|
||||
#endif
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val);
|
||||
int64_t getTimeLeft(enum timerIndex ind);
|
||||
#if defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
||||
|
@ -242,6 +242,8 @@ const char* getFunctionName(enum detFuncs func) {
|
||||
case F_GET_ADC_INVERT: return "F_GET_ADC_INVERT";
|
||||
case F_EXTERNAL_SAMPLING_SOURCE: return "F_EXTERNAL_SAMPLING_SOURCE";
|
||||
case F_EXTERNAL_SAMPLING: return "F_EXTERNAL_SAMPLING";
|
||||
case F_SET_STARTING_FRAME_NUMBER: return "F_SET_STARTING_FRAME_NUMBER";
|
||||
case F_GET_STARTING_FRAME_NUMBER: return "F_GET_STARTING_FRAME_NUMBER";
|
||||
default: return "Unknown Function";
|
||||
}
|
||||
}
|
||||
@ -324,6 +326,8 @@ void function_table() {
|
||||
flist[F_GET_ADC_INVERT] = &get_adc_invert;
|
||||
flist[F_EXTERNAL_SAMPLING_SOURCE] = &set_external_sampling_source;
|
||||
flist[F_EXTERNAL_SAMPLING] = &set_external_sampling;
|
||||
flist[F_SET_STARTING_FRAME_NUMBER] = &set_starting_frame_number;
|
||||
flist[F_GET_STARTING_FRAME_NUMBER] = &get_starting_frame_number;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
@ -3999,3 +4003,79 @@ int set_external_sampling(int file_des) {
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int set_starting_frame_number(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
uint64_t arg = 0;
|
||||
|
||||
if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logINFO, ("Setting starting frame number to %llu\n", arg));
|
||||
|
||||
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD))
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
if (arg == 0) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set starting frame number. Cannot be 0.\n");
|
||||
FILE_LOG(logERROR,(mess));
|
||||
}
|
||||
#ifdef EIGERD
|
||||
else if (arg > UDP_HEADER_MAX_FRAME_VALUE) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set starting frame number. Must be less then %lld (0x%llx)\n", UDP_HEADER_MAX_FRAME_VALUE, UDP_HEADER_MAX_FRAME_VALUE);
|
||||
FILE_LOG(logERROR,(mess));
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
ret = setStartingFrameNumber(arg);
|
||||
if (ret == FAIL) {
|
||||
sprintf(mess, "Could not set starting frame number. Failed to map address.\n");
|
||||
FILE_LOG(logERROR,(mess));
|
||||
}
|
||||
if (ret == OK) {
|
||||
uint64_t retval = 0;
|
||||
ret = getStartingFrameNumber(&retval);
|
||||
if (ret == FAIL) {
|
||||
sprintf(mess, "Could not get starting frame number. Failed to map address.\n");
|
||||
FILE_LOG(logERROR,(mess));
|
||||
} else {
|
||||
if (arg != retval) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set starting frame number. Set 0x%llx, but read 0x%llx\n", arg, retval);
|
||||
FILE_LOG(logERROR,(mess));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT64, UPDATE, NULL, 0);
|
||||
}
|
||||
|
||||
int get_starting_frame_number(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
uint64_t retval = -1;
|
||||
|
||||
FILE_LOG(logDEBUG1, ("Getting Starting frame number \n"));
|
||||
|
||||
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD))
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get
|
||||
ret = getStartingFrameNumber(&retval);
|
||||
if (ret == FAIL) {
|
||||
sprintf(mess, "Could not get starting frame number. Failed to map address.\n");
|
||||
FILE_LOG(logERROR,(mess));
|
||||
} else {
|
||||
FILE_LOG(logDEBUG1, ("Start frame number retval: %u\n", retval));
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT64, UPDATE, &retval, sizeof(retval));
|
||||
}
|
@ -103,3 +103,5 @@ int set_adc_invert(int);
|
||||
int get_adc_invert(int);
|
||||
int set_external_sampling_source(int);
|
||||
int set_external_sampling(int);
|
||||
int set_starting_frame_number(int);
|
||||
int get_starting_frame_number(int);
|
Reference in New Issue
Block a user