initial functions for mythen3

This commit is contained in:
maliakal_d 2019-08-22 15:55:27 +02:00
parent 72362b0334
commit 4b7ab98135
7 changed files with 129 additions and 25 deletions

View File

@ -1,4 +1,4 @@
add_executable(mythen3DetectorServer
add_executable(mythen3DetectorServer_virtual
slsDetectorFunctionList.c
../slsDetectorServer/slsDetectorServer.c
../slsDetectorServer/slsDetectorServer_funcs.c
@ -10,22 +10,22 @@ include_directories(
../../slsSupportLib/include
)
target_include_directories(mythen3DetectorServer
target_include_directories(mythen3DetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(mythen3DetectorServer
target_compile_definitions(mythen3DetectorServer_virtual
PUBLIC MYTHEN3D VIRTUAL STOP_SERVER
)
target_link_libraries(mythen3DetectorServer
target_link_libraries(mythen3DetectorServer_virtual
PUBLIC pthread rt
)
set_target_properties(mythen3DetectorServer PROPERTIES
set_target_properties(mythen3DetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS mythen3DetectorServer
install(TARGETS mythen3DetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -1,3 +1,4 @@
// stuff from Carlos
#pragma once
/* Definitions for FPGA*/
@ -5,5 +6,28 @@
/* Status register */
#define STATUS_REG (0x02 << MEM_MAP_SHIFT)
#define STATUS_REG (0x01 << MEM_MAP_SHIFT)
/* Set Cycles 64 bit register */
#define SET_CYCLES_LSB_REG (0x02 << MEM_MAP_SHIFT)
#define SET_CYCLES_MSB_REG (0x03 << MEM_MAP_SHIFT)
/* Set Frames 64 bit register */
#define SET_FRAMES_LSB_REG (0x04 << MEM_MAP_SHIFT)
#define SET_FRAMES_MSB_REG (0x05 << MEM_MAP_SHIFT)
/* Set Period 64 bit register tT = T x 50 ns */
#define SET_PERIOD_LSB_REG (0x06 << MEM_MAP_SHIFT)
#define SET_PERIOD_MSB_REG (0x07 << MEM_MAP_SHIFT)
/* Set Exptime 64 bit register eEXP = Exp x 25 ns */
#define SET_EXPTIME_LSB_REG (0x08 << MEM_MAP_SHIFT)
#define SET_EXPTIME_MSB_REG (0x09 << MEM_MAP_SHIFT)
/* Get Cycles 64 bit register */
#define GET_CYCLES_LSB_REG (0x0A << MEM_MAP_SHIFT)
#define GET_CYCLES_MSB_REG (0x0B << MEM_MAP_SHIFT)
/* Get Frames 64 bit register */
#define GET_FRAMES_LSB_REG (0x0C << MEM_MAP_SHIFT)
#define GET_FRAMES_MSB_REG (0x0D << MEM_MAP_SHIFT)

View File

@ -190,32 +190,64 @@ int getSpeed(enum speedVariable ind) {
int64_t setTimer(enum timerIndex ind, int64_t val) {
int64_t retval = -1;
switch(ind){
case FRAME_NUMBER:
case FRAME_NUMBER: // defined in sls_detector_defs.h (general)
if(val >= 0) {
FILE_LOG(logINFO, ("Setting #frames: %lld\n",(long long int)val));
}
retval = set64BitReg(val, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG); // defined in my RegisterDefs.h
FILE_LOG(logDEBUG1, ("Getting #frames: %lld\n", (long long int)retval));
break;
case ACQUISITION_TIME:
if(val >= 0){
FILE_LOG(logINFO, ("Setting exptime: %lldns\n", (long long int)val));
val *= (1E-3 * TEMP_CLK);
}
retval = set64BitReg(val, SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG) / (1E-3 * TEMP_CLK); // CLK defined in slsDetectorServer_defs.h
FILE_LOG(logDEBUG1, ("Getting exptime: %lldns\n", (long long int)retval));
break;
case FRAME_PERIOD:
if(val >= 0){
FILE_LOG(logINFO, ("Setting period: %lldns\n",(long long int)val));
val *= (1E-3 * TEMP_CLK);
}
retval = set64BitReg(val, SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG )/ (1E-3 * TEMP_CLK);
FILE_LOG(logDEBUG1, ("Getting period: %lldns\n", (long long int)retval));
break;
case CYCLES_NUMBER:
return -1;
if(val >= 0) {
FILE_LOG(logINFO, ("Setting #cycles: %lld\n", (long long int)val));
}
retval = set64BitReg(val, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG);
FILE_LOG(logDEBUG1, ("Getting #cycles: %lld\n", (long long int)retval));
break;
default:
FILE_LOG(logERROR, ("Timer Index not implemented for this detector: %d\n", ind));
break;
}
return -1;
return retval;
}
int validateTimer(enum timerIndex ind, int64_t val, int64_t retval) {
if (val < 0)
return OK;
switch(ind) {
case ACQUISITION_TIME:
case FRAME_PERIOD:
// convert to freq
val *= (1E-3 * TEMP_CLK);
// convert back to timer
val = (val) / (1E-3 * TEMP_CLK);
if (val != retval)
return FAIL;
break;
default:
break;
}
@ -227,6 +259,23 @@ int64_t getTimeLeft(enum timerIndex ind){
#ifdef VIRTUAL
return 0;
#endif
int64_t retval = -1;
switch(ind){
case FRAME_NUMBER:
retval = get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG);
FILE_LOG(logINFO, ("Getting number of frames left: %lld\n",(long long int)retval));
break;
case CYCLES_NUMBER:
retval = get64BitReg(GET_CYCLES_LSB_REG, GET_CYCLES_MSB_REG);
FILE_LOG(logINFO, ("Getting number of cycles left: %lld\n", (long long int)retval));
break;
default:
FILE_LOG(logERROR, ("Remaining Timer index not implemented for this detector: %d\n", ind));
break;
}
return -1;
}
@ -238,6 +287,7 @@ int startStateMachine(){
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
// set status to running
virtual_status = 1;
virtual_stop = 0;
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
@ -261,23 +311,30 @@ void* start_timer(void* arg) {
int frameNr = 0;
// loop over number of frames
for(frameNr=0; frameNr!= numFrames; ++frameNr ) {
int srcOffset = 0;
//check if virtual_stop is high, then break
// sleep for exposure time
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);
usleep(exp_ns / 1000);
clock_gettime(CLOCK_REALTIME, &end);
// calculate time left in period
int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime)
if (periodns > time_ns) {
usleep((periodns - time_ns)/ 1000);
}
// set register frames left
}
// set status to idle
virtual_status = 0;
return NULL;
}

View File

@ -8,4 +8,5 @@
/* Hardware Definitions */
#define NCHAN (128)
#define NCHIP (10)
#define NDAC (16)
#define NDAC (16)
#define TEMP_CLK (20) /* MHz */

View File

@ -18,6 +18,8 @@ const enum detectorType myDetectorType = JUNGFRAU;
const enum detectorType myDetectorType = CHIPTESTBOARD;
#elif MOENCHD
const enum detectorType myDetectorType = MOENCH;
#elif MYTHEN3D
const enum detectorType myDetectorType = MYTHEN3;
#else
const enum detectorType myDetectorType = GENERIC;
#endif
@ -1793,6 +1795,9 @@ int get_time_left(int file_des) {
case FRAME_PERIOD:
case DELAY_AFTER_TRIGGER:
case CYCLES_NUMBER:
#elif MYTHEN3D
case FRAME_NUMBER:
case CYCLES_NUMBER:
#endif
retval = getTimeLeft(ind);
FILE_LOG(logDEBUG1, ("Timer left index %d: %lld\n", ind, retval));
@ -2228,7 +2233,7 @@ int send_update(int file_des) {
if (n < 0) return printSocketReadError();
// delay
#ifndef EIGERD
#if !defined(EIGERD) && !defined(MYTHEN3D)
i64 = setTimer(DELAY_AFTER_TRIGGER,GET_FLAG);
n = sendData(file_des,&i64,sizeof(i64),INT64);
if (n < 0) return printSocketReadError();

View File

@ -75,6 +75,9 @@ void slsDetector::checkDetectorVersionCompatibility() {
case MOENCH:
arg = APIMOENCH;
break;
case MYTHEN3:
arg = APIMYTHEN3;
break;
default:
throw NotImplementedError(
"Check version compatibility is not implemented for this detector");
@ -385,6 +388,9 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
case MOENCH:
shm()->rxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
break;
case MYTHEN3:
shm()->rxFramesPerFile = MYTHEN3_MAX_FRAMES_PER_FILE;
break;
default:
break;
}
@ -739,8 +745,8 @@ void slsDetector::updateCachedDetectorVariables() {
shm()->dynamicRange = i32;
// settings
if ((shm()->myDetectorType != CHIPTESTBOARD) &&
(shm()->myDetectorType != MOENCH)) {
if (shm()->myDetectorType == EIGER ||
shm()->myDetectorType == JUNGFRAU || shm()->myDetectorType == GOTTHARD) {
n += client.Receive(&i32, sizeof(i32));
shm()->currentSettings = static_cast<detectorSettings>(i32);
}
@ -773,7 +779,7 @@ void slsDetector::updateCachedDetectorVariables() {
shm()->timerValue[FRAME_PERIOD] = i64;
// delay
if (shm()->myDetectorType != EIGER) {
if (shm()->myDetectorType != EIGER && shm()->myDetectorType != MYTHEN3 ) {
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[DELAY_AFTER_TRIGGER] = i64;
}

View File

@ -63,6 +63,7 @@
#define EIGER_MAX_FRAMES_PER_FILE 10000
#define JFRAU_MAX_FRAMES_PER_FILE 10000
#define CTB_MAX_FRAMES_PER_FILE 20000
#define MYTHEN3_MAX_FRAMES_PER_FILE 10000
#define DEFAULT_STREAMING_TIMER_IN_MS 200
@ -1138,6 +1139,16 @@ struct detParameters {
nGappixelsX = 6;
nGappixelsY = 1;
break;
case slsDetectorDefs::detectorType::MYTHEN3:
nChanX = 128;
nChanY = 1;
nChipX = 10;
nChipY = 1;
nDacs = 16;
dynamicRange = 16;
nGappixelsX = 0;
nGappixelsY = 0;
break;
default:
throw sls::RuntimeError(
"Unknown detector type! " +