diff --git a/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt b/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt index 821df3f4a..f9e195018 100644 --- a/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt +++ b/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt @@ -22,7 +22,7 @@ target_include_directories(gotthard2DetectorServer_virtual ) target_compile_definitions(gotthard2DetectorServer_virtual - PUBLIC GOTTHARD2D VIRTUAL STOP_SERVER + PUBLIC GOTTHARD2D VIRTUAL STOP_SERVER DEBUG1 ) target_link_libraries(gotthard2DetectorServer_virtual diff --git a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h index 45aab3351..b4a5cc169 100644 --- a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h +++ b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h @@ -147,7 +147,7 @@ /* Packetizer -------------------------------------------------------------*/ -/* Packetizer Config Register*/ +/* Packetizer Config Register */ #define PKT_CONFIG_REG (0x00 * REG_OFFSET + BASE_PKT) #define PKT_CONFIG_NRXR_MAX_OFST (0) @@ -155,6 +155,21 @@ #define PKT_CONFIG_RXR_START_ID_OFST (8) #define PKT_CONFIG_RXR_START_ID_MSK (0x0000003F << PKT_CONFIG_RXR_START_ID_OFST) +/* Module Coordinates Register */ +#define COORD_0_REG (0x02 * REG_OFFSET + BASE_PKT) +#define COORD_ROW_OFST (0) +#define COORD_ROW_MSK (0x0000FFFF << COORD_ROW_OFST) +#define COORD_COL_OFST (16) +#define COORD_COL_MSK (0x0000FFFF << COORD_COL_OFST) + +/* Module ID Register */ +#define COORD_1_REG (0x03 * REG_OFFSET + BASE_PKT) +#define COORD_RESERVED_OFST (0) +#define COORD_RESERVED_MSK (0x0000FFFF << COORD_RESERVED_OFST) +#define COORD_ID_OFST (16) // Not connected in firmware TODO +#define COORD_ID_MSK (0x0000FFFF << COORD_ID_OFST) // Not connected in firmware TODO + + /* Flow control registers --------------------------------------------------*/ /* Flow status Register*/ diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 95730ebf8..f9c37e4ab 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index c5cd3a1c9..fba0c9f43 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -24,6 +24,7 @@ extern int debugflag; extern int checkModuleFlag; extern udpStruct udpDetails; +extern const enum detectorType myDetectorType; int initError = OK; int initCheckDone = 0; @@ -422,10 +423,12 @@ void setupDetector() { // power on chip powerChip(1); +#ifndef VIRTUAL // also sets default dac and on chip dac values if (readConfigFile() == FAIL) { return; } +#endif // set burst mode will take in burstType and also set it burstType = DEFAULT_BURST_TYPE; setBurstMode(DEFAULT_BURST_MODE); @@ -1169,7 +1172,35 @@ void calcChecksum(udp_header* udp) { int setDetectorPosition(int pos[]) { memcpy(detPos, pos, sizeof(detPos)); - return OK; + + uint32_t addr = COORD_0_REG; + int value = 0; + int valueRead = 0; + int ret = OK; + + // row + value = detPos[X]; + bus_w(addr, (bus_r(addr) &~COORD_ROW_MSK) | ((value << COORD_ROW_OFST) & COORD_ROW_MSK)); + valueRead = ((bus_r(addr) & COORD_ROW_MSK) >> COORD_ROW_OFST); + if (valueRead != value) { + FILE_LOG(logERROR, ("Could not set row. Set %d, read %d\n", value, valueRead)); + ret = FAIL; + } + + // col + value = detPos[Y]; + bus_w(addr, (bus_r(addr) &~COORD_COL_MSK) | ((value << COORD_COL_OFST) & COORD_COL_MSK)); + valueRead = ((bus_r(addr) & COORD_COL_MSK) >> COORD_COL_OFST); + if (valueRead != value) { + FILE_LOG(logERROR, ("Could not set column. Set %d, read %d\n", value, valueRead)); + ret = FAIL; + } + + if (ret == OK) { + FILE_LOG(logINFO, ("\tPosition set to [%d, %d]\n", detPos[X], detPos[Y])); + } + + return ret; } int* getDetectorPosition() { @@ -1847,6 +1878,8 @@ void* start_timer(void* arg) { int numFrames = (getNumFrames() * getNumTriggers() ); int64_t exp_ns = getExpTime(); + int datasize = 2560; + int packetsize = datasize + sizeof(sls_detector_header); int frameNr = 0; @@ -1864,6 +1897,22 @@ void* start_timer(void* arg) { usleep(exp_ns / 1000); clock_gettime(CLOCK_REALTIME, &end); + char packetData[packetsize]; + memset(packetData, 0, packetsize); + // set header + sls_detector_header* header = (sls_detector_header*)(packetData); + header->frameNumber = frameNr; + header->packetNumber = 0; + header->modId = 0; + header->row = detPos[X]; + header->column = detPos[Y]; + header->detType = (uint16_t)myDetectorType; + header->version = SLS_DETECTOR_HEADER_VERSION - 1; + + // send 1 packet = 1 frame + sendUDPPacket(0, packetData, packetsize); + FILE_LOG(logINFO, ("Sent frame: %d\n", frameNr)); + // calculate time left in period int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec)); diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 8b83cd5a9..1055bc82e 100755 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -24,6 +24,7 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern udpStruct udpDetails; +extern const enum detectorType myDetectorType; int initError = OK; int initCheckDone = 0; @@ -1667,7 +1668,7 @@ void* start_timer(void* arg) { usleep(exp_us); - const int size = datasize + 112; + const int size = datasize + sizeof(sls_detector_header); char packetData[size]; memset(packetData, 0, sizeof(sls_detector_header)); @@ -1679,6 +1680,11 @@ void* start_timer(void* arg) { sls_detector_header* header = (sls_detector_header*)(packetData); header->frameNumber = frameNr; header->packetNumber = i; + header->modId = 0; + header->row = detPos[X]; + header->column = detPos[Y]; + header->detType = (uint16_t)myDetectorType; + header->version = SLS_DETECTOR_HEADER_VERSION - 1; // fill data memcpy(packetData + sizeof(sls_detector_header), imageData + srcOffset, datasize); srcOffset += datasize; diff --git a/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c b/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c index b8494e3be..91df2f2f1 100755 --- a/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c +++ b/slsDetectorServers/slsDetectorServer/src/ASIC_Driver.c @@ -38,6 +38,9 @@ int ASIC_Driver_Set (int index, int length, char* buffer) { FILE_LOG(logDEBUG1, ("\t]\n")); } +#ifdef VIRTUAL + return OK; +#endif int fd=open(fname, O_RDWR); if (fd == -1) { FILE_LOG(logERROR, ("Could not open file %s for writing to control ASIC (%d)\n", fname, index)); diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 45e4e8bec..1c06c6949 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -9,4 +9,4 @@ #define APICTB 0x191210 #define APIEIGER 0x200110 #define APIMYTHEN3 0x200120 -#define APIGOTTHARD2 0x200120 +#define APIGOTTHARD2 0x200121