diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 5db80ec49..393f0753a 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 37db55a97..333c4a93b 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index c825514e9..4dd91e5de 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 855ab1396..f53bbc07d 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -473,8 +473,8 @@ void setupDetector() { // hv DAC6571_SetDefines(HV_HARD_MAX_VOLTAGE, HV_DRIVER_FILE_NAME); // dacs - LTC2620_D_SetDefines(DAC_MIN_MV, DAC_MAX_MV, DAC_DRIVER_FILE_NAME, NDAC, 1, - 0, ""); + LTC2620_D_SetDefines(DAC_MIN_MV, DAC_MAX_MV, DAC_DRIVER_FILE_NAME, NDAC, 0, + ""); // on chip dacs ASIC_Driver_SetDefines(ONCHIP_DAC_DRIVER_FILE_NAME); setTimingSource(DEFAULT_TIMING_SOURCE); diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 84b25b03f..fc95ba9f8 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index bec071069..be27b5dd7 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 109df6735..3a7336a30 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 574c57b79..c879e7748 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index d7b1048aa..03d6a2d9e 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -486,8 +486,8 @@ void setupDetector() { // hv DAC6571_SetDefines(HV_HARD_MAX_VOLTAGE, HV_DRIVER_FILE_NAME); // dac - LTC2620_D_SetDefines(DAC_MIN_MV, DAC_MAX_MV, DAC_DRIVER_FILE_NAME, NDAC, 1, - 0, ""); + LTC2620_D_SetDefines(DAC_MIN_MV, DAC_MAX_MV, DAC_DRIVER_FILE_NAME, NDAC, 0, + ""); resetCore(); resetPeripheral(); diff --git a/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h b/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h index 4a9cfd72d..f11139ac2 100644 --- a/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h +++ b/slsDetectorServers/slsDetectorServer/include/LTC2620_Driver.h @@ -5,10 +5,12 @@ #include void LTC2620_D_SetDefines(int hardMinV, int hardMaxV, char *driverfname, - int numdacs, int numdevices, int startingDeviceIndex, + int numdacs, int numpowers, char *powerdownDriverfname); int LTC2620_D_GetMaxNumSteps(); int LTC2620_D_GetPowerDownValue(); +int LTC2620_D_GetMinInput(); +int LTC2620_D_GetMaxInput(); /** * Convert voltage to dac units diff --git a/slsDetectorServers/slsDetectorServer/include/programViaArm.h b/slsDetectorServers/slsDetectorServer/include/programViaArm.h index d2434b94d..2adee7178 100644 --- a/slsDetectorServers/slsDetectorServer/include/programViaArm.h +++ b/slsDetectorServers/slsDetectorServer/include/programViaArm.h @@ -5,8 +5,8 @@ #include int resetFPGA(char *mess); -int loadDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex); +int loadDeviceTree(char *mess); int checksBeforeCreatingDeviceTree(char *mess); int createDeviceTree(char *mess); -int verifyDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex); \ No newline at end of file +int verifyDeviceTree(char *mess); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 4599f2b5a..985c1bdb1 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -184,7 +184,7 @@ uint32_t readRegister16And32(uint32_t offset); #if defined(XILINX_CHIPTESTBOARDD) void cleanFifos(); void resetFlow(); -int waitTranseiverReset(char *mess); +int waitTransceiverReset(char *mess); #ifdef VIRTUAL void setTransceiverAlignment(int align); #endif @@ -424,6 +424,8 @@ int getPower(); void setPower(enum DACINDEX ind, int val); void powerOff(); #elif XILINX_CHIPTESTBOARDD +int isPowerValid(enum DACINDEX ind, int val); + int getPower(); void setPower(enum DACINDEX ind, int val); #endif diff --git a/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c b/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c index 3de5a7c36..c92c111f4 100644 --- a/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c +++ b/slsDetectorServers/slsDetectorServer/src/LTC2620_Driver.c @@ -9,6 +9,7 @@ /* LTC2620 DAC DEFINES */ #define LTC2620_D_PWR_DOWN_VAL (-100) +#define LTC2620_D_MIN_DAC_VAL (0) #define LTC2620_D_MAX_DAC_VAL (4095) // 12 bits #define LTC2620_D_MAX_STEPS (LTC2620_D_MAX_DAC_VAL + 1) @@ -18,17 +19,15 @@ int LTC2620_D_HardMaxVoltage = 0; char LTC2620_D_DriverFileName[MAX_STR_LENGTH]; char LTC2620_D_PowerDownDriverFileName[MAX_STR_LENGTH]; int LTC2620_D_NumDacs = 0; -int LTC2620_D_NumDevices = 0; -int LTC2620_D_NumChannelsPerDevice = 0; -int LTC2620_D_DacDriverStartingDeviceIndex = 0; +int LTC2620_D_NumDacsOnly = 0; void LTC2620_D_SetDefines(int hardMinV, int hardMaxV, char *driverfname, - int numdacs, int numdevices, int startingDeviceIndex, + int numdacs, int numpowers, char *powerdownDriverfname) { LOG(logINFOBLUE, ("Configuring DACs (LTC2620) to %s\n\t (numdacs:%d, hard min:%d, hard " - "max: %dmV, idev:%d)\n", - driverfname, numdacs, hardMinV, hardMaxV, startingDeviceIndex)); + "max: %dmV)\n", + driverfname, numdacs, hardMinV, hardMaxV)); LTC2620_D_HardMinVoltage = hardMinV; LTC2620_D_HardMaxVoltage = hardMaxV; memset(LTC2620_D_DriverFileName, 0, MAX_STR_LENGTH); @@ -36,15 +35,17 @@ void LTC2620_D_SetDefines(int hardMinV, int hardMaxV, char *driverfname, memset(LTC2620_D_PowerDownDriverFileName, 0, MAX_STR_LENGTH); strcpy(LTC2620_D_PowerDownDriverFileName, powerdownDriverfname); LTC2620_D_NumDacs = numdacs; - LTC2620_D_NumDevices = numdevices; - LTC2620_D_NumChannelsPerDevice = LTC2620_D_NumDacs / LTC2620_D_NumDevices; - LTC2620_D_DacDriverStartingDeviceIndex = startingDeviceIndex; + LTC2620_D_NumDacsOnly = numdacs - numpowers; } int LTC2620_D_GetMaxNumSteps() { return LTC2620_D_MAX_STEPS; } int LTC2620_D_GetPowerDownValue() { return LTC2620_D_PWR_DOWN_VAL; } +int LTC2620_D_GetMinInput() { return LTC2620_D_MIN_DAC_VAL; } + +int LTC2620_D_GetMaxInput() { return LTC2620_D_MAX_DAC_VAL; } + int LTC2620_D_VoltageToDac(int voltage, int *dacval) { return ConvertToDifferentRange(LTC2620_D_HardMinVoltage, LTC2620_D_HardMaxVoltage, 0, @@ -94,7 +95,10 @@ int LTC2620_D_SetDACValue(int dacnum, int val, int mV, char *dacname, int dacmV = val; if (mV) { ret = LTC2620_D_VoltageToDac(val, dacval); - } else if (val >= 0) { + } + + // mV only for print out (dont convert to mV for power regulators) + else if (val >= 0 && dacnum < LTC2620_D_NumDacsOnly) { // do not convert power down dac val ret = LTC2620_D_DacToVoltage(val, &dacmV); } @@ -109,8 +113,16 @@ int LTC2620_D_SetDACValue(int dacnum, int val, int mV, char *dacname, // print and set #ifdef XILINX_CHIPTESTBOARDD if (*dacval >= 0) { - LOG(logINFO, ("Setting DAC %2d [%-6s] : %d dac (%d mV)\n", dacnum, - dacname, *dacval, dacmV)); + // also print mV + if (dacnum < LTC2620_D_NumDacsOnly) { + LOG(logINFO, ("Setting DAC %2d [%-6s] : %d dac (%d mV)\n", + dacnum, dacname, *dacval, dacmV)); + } + // do not print mV for power regulators + else { + LOG(logINFO, ("Setting Power DAC%2d [%-6s] : %d dac \n", dacnum, + dacname, *dacval)); + } } #else if ((*dacval >= 0) || (*dacval == LTC2620_D_PWR_DOWN_VAL)) { @@ -125,10 +137,7 @@ int LTC2620_D_SetDACValue(int dacnum, int val, int mV, char *dacname, char fname[MAX_STR_LENGTH]; memset(fname, 0, MAX_STR_LENGTH); #ifdef XILINX_CHIPTESTBOARDD - int idev = LTC2620_D_DacDriverStartingDeviceIndex + - (dacnum / LTC2620_D_NumChannelsPerDevice); - int idac = dacnum % LTC2620_D_NumChannelsPerDevice; - sprintf(fname, fnameFormat, idev, idac); + sprintf(fname, fnameFormat, dacnum); #else sprintf(fname, "%s%d", fnameFormat, dacnum); #endif diff --git a/slsDetectorServers/slsDetectorServer/src/arm64.c b/slsDetectorServers/slsDetectorServer/src/arm64.c index 2cbc4afda..ae4685911 100644 --- a/slsDetectorServers/slsDetectorServer/src/arm64.c +++ b/slsDetectorServers/slsDetectorServer/src/arm64.c @@ -13,9 +13,9 @@ /* global variables */ #define CSP0 (0xB0080000) #define CSP1 (0xB0050000) // udp -#define MEM_SIZE (0x10000) -//#define MEM_SIZE_CSP0 (4096) -//#define MEM_SIZE_CSP1 (2 * 4096) +#define MEM_SIZE_CSP0 (0x10000) +#define MEM_SIZE_CSP1 (0x2000) // smaller size for udp + u_int32_t *csp0base = 0; u_int32_t *csp1base = 0; @@ -52,6 +52,7 @@ u_int32_t writeRegister(u_int32_t offset, u_int32_t data) { int mapCSP0(void) { u_int32_t csps[2] = {CSP0, CSP1}; u_int32_t **cspbases[2] = {&csp0base, &csp1base}; + u_int32_t memsize[2] = {MEM_SIZE_CSP0, MEM_SIZE_CSP1}; char names[2][10] = {"csp0base", "csp1base"}; for (int i = 0; i < 2; ++i) { @@ -59,10 +60,10 @@ int mapCSP0(void) { if (*cspbases[i] == 0) { LOG(logINFO, ("Mapping memory for %s\n", names[i])); #ifdef VIRTUAL - *cspbases[i] = malloc(MEM_SIZE); + *cspbases[i] = malloc(memsize[i]); if (*cspbases[i] == NULL) { LOG(logERROR, - ("Could not allocate virtual memory for %s.\n", names[i])); + ("Could not allocate virtual memory of size %d for %s.\n", memsize[i], names[i])); return FAIL; } LOG(logINFO, ("memory allocated for %s\n", names[i])); @@ -75,15 +76,15 @@ int mapCSP0(void) { LOG(logDEBUG1, ("/dev/mem opened for %s, (CSP:0x%x)\n", names[i], csps[i])); *cspbases[i] = - (u_int32_t *)mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, + (u_int32_t *)mmap(0, memsize[i], PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, csps[i]); if (*cspbases[i] == MAP_FAILED) { LOG(logERROR, ("Can't map memmory area for %s\n", names[i])); return FAIL; } #endif - LOG(logINFO, ("%s mapped from %p to %p,(CSP:0x%x) \n", names[i], - *cspbases[i], *cspbases[i] + MEM_SIZE, csps[i])); + LOG(logINFO, ("%s mapped of size %d from %p to %p,(CSP:0x%x) \n", names[i], memsize[i], + *cspbases[i], *cspbases[i] + memsize[i], csps[i])); // LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); } else LOG(logINFO, ("Memory %s already mapped before\n", names[i])); diff --git a/slsDetectorServers/slsDetectorServer/src/programViaArm.c b/slsDetectorServers/slsDetectorServer/src/programViaArm.c index adc05ac8e..61e8c029e 100644 --- a/slsDetectorServers/slsDetectorServer/src/programViaArm.c +++ b/slsDetectorServers/slsDetectorServer/src/programViaArm.c @@ -35,8 +35,8 @@ int resetFPGA(char *mess) { return OK; } -int loadDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex) { - if (verifyDeviceTree(mess, adcDeviceIndex, dacDeviceIndex) == OK) +int loadDeviceTree(char *mess) { + if (verifyDeviceTree(mess) == OK) return OK; if (checksBeforeCreatingDeviceTree(mess) == FAIL) @@ -45,7 +45,7 @@ int loadDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex) { if (createDeviceTree(mess) == FAIL) return FAIL; - if (verifyDeviceTree(mess, adcDeviceIndex, dacDeviceIndex) == FAIL) { + if (verifyDeviceTree(mess) == FAIL) { LOG(logERROR, ("Device tree loading failed at verification\n")); return FAIL; } @@ -129,10 +129,8 @@ int createDeviceTree(char *mess) { return OK; } -int verifyDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex) { +int verifyDeviceTree(char *mess) { LOG(logINFOBLUE, ("Verifying Device Tree...\n")); - *adcDeviceIndex = 1; - *dacDeviceIndex = 2; #ifndef VIRTUAL // check if iio:device0-4 exists in device tree destination @@ -170,8 +168,6 @@ int verifyDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex) { strstr(retvals, deviceNames[hardcodedDeviceIndex + 1]) != NULL) { ++hardcodedDeviceIndex; - *adcDeviceIndex = 4; - *dacDeviceIndex = 1; } else { snprintf( mess, MAX_STR_LENGTH, @@ -188,9 +184,6 @@ int verifyDeviceTree(char *mess, int *adcDeviceIndex, int *dacDeviceIndex) { hardcodedDeviceIndex = 1; } #endif - LOG(logINFOBLUE, ("Device tree verified successfully [temp: 0, adc:%d, " - "dac:%d, %d, %d]\n", - *adcDeviceIndex, *dacDeviceIndex, *dacDeviceIndex + 1, - *dacDeviceIndex + 2)); + LOG(logINFOBLUE, ("Device tree verified successfully\n")); return OK; } \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 3658ec917..507611403 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1297,7 +1297,7 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) { ind, getVLimit()); LOG(logERROR, (mess)); } -#ifdef CHIPTESTBOARDD + else if (!isPowerValid(serverDacIndex, val)) { ret = FAIL; sprintf( @@ -1306,10 +1306,14 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) { "should be between %d and %d mV\n", ind, (serverDacIndex == D_PWR_IO ? VIO_MIN_MV : POWER_RGLTR_MIN), +#ifdef CHIPTESTBOARDD (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); +#else + POWER_RGLTR_MAX); +#endif LOG(logERROR, (mess)); } -#endif + else { setPower(serverDacIndex, val); } @@ -2022,105 +2026,101 @@ int acquire(int blocking, int file_des) { #if defined(JUNGFRAUD) // chipv1.1 has to be configured before acquisition if (getChipVersion() == 11 && !isChipConfigured()) { - ret = FAIL; - strcpy(mess, - "Could not start acquisition. Chip is not configured. " - "Power it on to configure it.\n"); - LOG(logERROR, (mess)); - } else + ret = FAIL; + strcpy(mess, "Could not start acquisition. Chip is not configured. " + "Power it on to configure it.\n"); + LOG(logERROR, (mess)); + } else #endif #if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD) - if ((getReadoutMode() == ANALOG_AND_DIGITAL || - getReadoutMode() == ANALOG_ONLY) && - (getNumAnalogSamples() <= 0)) { - ret = FAIL; - sprintf(mess, - "Could not start acquisition. Invalid number of analog " - "samples: %d.\n", - getNumAnalogSamples()); - LOG(logERROR, (mess)); - } else if ((getReadoutMode() == ANALOG_AND_DIGITAL || - getReadoutMode() == DIGITAL_ONLY || - getReadoutMode() == DIGITAL_AND_TRANSCEIVER) && - (getNumDigitalSamples() <= 0)) { - ret = FAIL; - sprintf( - mess, + if ((getReadoutMode() == ANALOG_AND_DIGITAL || + getReadoutMode() == ANALOG_ONLY) && + (getNumAnalogSamples() <= 0)) { + ret = FAIL; + sprintf(mess, + "Could not start acquisition. Invalid number of analog " + "samples: %d.\n", + getNumAnalogSamples()); + LOG(logERROR, (mess)); + } else if ((getReadoutMode() == ANALOG_AND_DIGITAL || + getReadoutMode() == DIGITAL_ONLY || + getReadoutMode() == DIGITAL_AND_TRANSCEIVER) && + (getNumDigitalSamples() <= 0)) { + ret = FAIL; + sprintf(mess, "Could not start acquisition. Invalid number of digital " "samples: %d.\n", getNumDigitalSamples()); - LOG(logERROR, (mess)); - } else if ((getReadoutMode() == TRANSCEIVER_ONLY || - getReadoutMode() == DIGITAL_AND_TRANSCEIVER) && - (getNumTransceiverSamples() <= 0)) { - ret = FAIL; - sprintf(mess, - "Could not start acquisition. Invalid number of " - "transceiver " - "samples: %d.\n", - getNumTransceiverSamples()); - LOG(logERROR, (mess)); - } else + LOG(logERROR, (mess)); + } else if ((getReadoutMode() == TRANSCEIVER_ONLY || + getReadoutMode() == DIGITAL_AND_TRANSCEIVER) && + (getNumTransceiverSamples() <= 0)) { + ret = FAIL; + sprintf(mess, + "Could not start acquisition. Invalid number of " + "transceiver " + "samples: %d.\n", + getNumTransceiverSamples()); + LOG(logERROR, (mess)); + } else #endif #ifdef EIGERD - // check for hardware mac and hardware ip - if (udpDetails[0].srcmac != getDetectorMAC()) { - ret = FAIL; - uint64_t sourcemac = getDetectorMAC(); - char src_mac[MAC_ADDRESS_SIZE]; - getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac); - sprintf(mess, - "Invalid udp source mac address for this detector. " - "Must be " - "same as hardware detector mac address %s\n", - src_mac); - LOG(logERROR, (mess)); - } else if (!enableTenGigabitEthernet(GET_FLAG) && - (udpDetails[0].srcip != getDetectorIP())) { - ret = FAIL; - uint32_t sourceip = getDetectorIP(); - char src_ip[INET_ADDRSTRLEN]; - getIpAddressinString(src_ip, sourceip); - sprintf( - mess, - "Invalid udp source ip address for this detector. Must " - "be " - "same as hardware detector ip address %s in 1G readout " - "mode \n", - src_ip); - LOG(logERROR, (mess)); - } else + // check for hardware mac and hardware ip + if (udpDetails[0].srcmac != getDetectorMAC()) { + ret = FAIL; + uint64_t sourcemac = getDetectorMAC(); + char src_mac[MAC_ADDRESS_SIZE]; + getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac); + sprintf(mess, + "Invalid udp source mac address for this detector. " + "Must be " + "same as hardware detector mac address %s\n", + src_mac); + LOG(logERROR, (mess)); + } else if (!enableTenGigabitEthernet(GET_FLAG) && + (udpDetails[0].srcip != getDetectorIP())) { + ret = FAIL; + uint32_t sourceip = getDetectorIP(); + char src_ip[INET_ADDRSTRLEN]; + getIpAddressinString(src_ip, sourceip); + sprintf(mess, + "Invalid udp source ip address for this detector. Must " + "be " + "same as hardware detector ip address %s in 1G readout " + "mode \n", + src_ip); + LOG(logERROR, (mess)); + } else #endif - if (configured == FAIL) { - ret = FAIL; - strcpy(mess, "Could not start acquisition because "); - strcat(mess, configureMessage); - LOG(logERROR, (mess)); - } else if (sharedMemory_getScanStatus() == RUNNING) { - ret = FAIL; - strcpy(mess, - "Could not start acquisition because a scan is " - "already running!\n"); - LOG(logERROR, (mess)); - } else { - memset(scanErrMessage, 0, MAX_STR_LENGTH); - sharedMemory_setScanStop(0); - sharedMemory_setScanStatus(IDLE); // if it was error - if (pthread_create(&pthread_tid, NULL, &start_state_machine, - &blocking)) { - ret = FAIL; - strcpy(mess, "Could not start acquisition thread!\n"); - LOG(logERROR, (mess)); - } else { - // wait for blocking always (scan or not) - // non blocking-no scan also wait (for error message) - // non blcoking-scan dont wait (there is - // scanErrorMessage) - if (blocking || !scan) { - pthread_join(pthread_tid, NULL); - } - } + if (configured == FAIL) { + ret = FAIL; + strcpy(mess, "Could not start acquisition because "); + strcat(mess, configureMessage); + LOG(logERROR, (mess)); + } else if (sharedMemory_getScanStatus() == RUNNING) { + ret = FAIL; + strcpy(mess, "Could not start acquisition because a scan is " + "already running!\n"); + LOG(logERROR, (mess)); + } else { + memset(scanErrMessage, 0, MAX_STR_LENGTH); + sharedMemory_setScanStop(0); + sharedMemory_setScanStatus(IDLE); // if it was error + if (pthread_create(&pthread_tid, NULL, &start_state_machine, + &blocking)) { + ret = FAIL; + strcpy(mess, "Could not start acquisition thread!\n"); + LOG(logERROR, (mess)); + } else { + // wait for blocking always (scan or not) + // non blocking-no scan also wait (for error message) + // non blcoking-scan dont wait (there is + // scanErrorMessage) + if (blocking || !scan) { + pthread_join(pthread_tid, NULL); } + } + } } return Server_SendResult(file_des, INT32, NULL, 0); } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/Makefile b/slsDetectorServers/xilinx_ctbDetectorServer/Makefile index e8589a5c7..06a4d986d 100755 --- a/slsDetectorServers/xilinx_ctbDetectorServer/Makefile +++ b/slsDetectorServers/xilinx_ctbDetectorServer/Makefile @@ -23,6 +23,10 @@ SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(m OBJS = $(SRCS:.c=.o) all: clean $(PROGS) + +local: CC := gcc +local: clean $(PROGS) + version: clean versioning $(PROGS) boot: $(OBJS) diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer index 269579caf..1428e465c 100755 Binary files a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer and b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer differ diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 5317df841..aa3d3bf17 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -39,8 +39,6 @@ char initErrorMessage[MAX_STR_LENGTH]; int detPos[2] = {0, 0}; -int adcDeviceIndex = 0; -int dacDeviceIndex = 0; int chipConfigured = 0; int analogEnable = 0; int digitalEnable = 0; @@ -75,8 +73,7 @@ void basictests() { return; } - initError = - loadDeviceTree(initErrorMessage, &adcDeviceIndex, &dacDeviceIndex); + initError = loadDeviceTree(initErrorMessage); if (initError == FAIL) { return; } @@ -390,19 +387,18 @@ void setupDetector() { initializePatternWord(); #endif // initialization only at start up (restart fpga) - initError = waitTranseiverReset(initErrorMessage); - if (initError == FAIL) { - return; - } - // power off chip + // initError = waitTransceiverReset(initErrorMessage); + // if (initError == FAIL) { + // return; + // } + // // power off chip initError = powerChip(0, initErrorMessage); - if (initError == FAIL) { - return; - } + // if (initError == FAIL) { + // return; + // } - LTC2620_D_SetDefines(DAC_MAX_MV, DAC_MIN_MV, DAC_DRIVER_FILE_NAME, NDAC, - DAC_DRIVER_NUM_DEVICES, dacDeviceIndex, - DAC_POWERDOWN_DRIVER_FILE_NAME); + LTC2620_D_SetDefines(DAC_MIN_MV, DAC_MAX_MV, DAC_DRIVER_FILE_NAME, NDAC, + NPWR, DAC_POWERDOWN_DRIVER_FILE_NAME); LOG(logINFOBLUE, ("Powering down all dacs\n")); for (int idac = 0; idac < NDAC; ++idac) { setDAC(idac, LTC2620_D_GetPowerDownValue(), 0); @@ -458,7 +454,7 @@ void resetFlow() { bus_w(FLOW_CONTROL_REG, bus_r(FLOW_CONTROL_REG) & ~RST_F_MSK); } -int waitTranseiverReset(char *mess) { +int waitTransceiverReset(char *mess) { #ifndef VIRTUAL int resetTransceiverDone = (bus_r(TRANSCEIVERSTATUS) & RESETRXDONE_MSK); int times = 0; @@ -556,7 +552,7 @@ int powerChip(int on, char *mess) { POWER_VCC_C_MSK | POWER_VCC_D_MSK; if (on) { LOG(logINFOBLUE, ("Powering chip: on\n")); - bus_w(addr, bus_r(addr) & ~mask); + bus_w(addr, bus_r(addr) | mask); if (configureChip(mess) == FAIL) return FAIL; @@ -566,7 +562,7 @@ int powerChip(int on, char *mess) { chipConfigured = 1; } else { LOG(logINFOBLUE, ("Powering chip: off\n")); - bus_w(addr, bus_r(addr) | mask); + bus_w(addr, bus_r(addr) & ~mask); chipConfigured = 0; @@ -588,7 +584,7 @@ int getPowerChip() { uint32_t addr = CTRL_REG; uint32_t mask = POWER_VIO_MSK | POWER_VCC_A_MSK | POWER_VCC_B_MSK | POWER_VCC_C_MSK | POWER_VCC_D_MSK; - return (((bus_r(addr) & mask) == mask) ? 0 : 1); + return (((bus_r(addr) & mask) == mask) ? 1 : 0); } int configureChip(char *mess) { @@ -981,21 +977,8 @@ void setDAC(enum DACINDEX ind, int val, int mV) { LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dacName, val, (mV ? "mV" : "dac units"))); int dacval = val; - -#ifdef VIRTUAL - LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dacName, val, - (mV ? "mV" : "dac units"))); - if (!mV) { - dacValues[ind] = val; - } - // convert to dac units - else if (LTC2620_D_VoltageToDac(val, &dacval) == OK) { - dacValues[ind] = dacval; - } -#else if (LTC2620_D_SetDACValue((int)ind, val, mV, dacName, &dacval) == OK) dacValues[ind] = dacval; -#endif } int getDAC(enum DACINDEX ind, int mV) { @@ -1045,74 +1028,91 @@ void setVLimit(int l) { vLimit = l; } -int getPower(enum DACINDEX ind) { - // check power enable first - uint32_t addr = CTRL_REG; - uint32_t offset = POWER_VCC_A_OFST + (int)(D_PWR_A - ind); - if (ind == D_PWR_IO) - offset = POWER_VIO_OFST; - uint32_t mask = (1 << offset); - if ((bus_r(addr) & mask) != 0) { - LOG(logINFO, ("Power for dac %d is off\n", ind)); +int isPowerValid(enum DACINDEX ind, int val) { + char *powerNames[] = {PWR_NAMES}; + int pwrIndex = (int)(ind - D_PWR_D); + + int min = POWER_RGLTR_MIN; + if (!strcmp(powerNames[pwrIndex], "IO")) { + min = VIO_MIN_MV; + } + + // not power_rgltr_max because it is allowed only upto vchip max - 200 + if (val != 0 && (val != LTC2620_D_GetPowerDownValue()) && + (val < min || val > POWER_RGLTR_MAX)) { + LOG(logERROR, + ("Invalid value of %d mV for Power V%s. Is not between %d and " + "%d mV\n", + val, powerNames[pwrIndex], min, POWER_RGLTR_MAX)); return 0; } + return 1; +} + +int getPower(enum DACINDEX ind) { + char *powerNames[] = {PWR_NAMES}; + int pwrIndex = (int)(ind - D_PWR_D); // check dac value // not set yet if (dacValues[ind] == -1) { LOG(logERROR, - ("Power enabled, but unknown dac value for power index %d!", ind)); + ("Unknown dac value for Power V%s!\n", powerNames[pwrIndex])); return -1; } // dac powered off if (dacValues[ind] == LTC2620_D_GetPowerDownValue()) { - LOG(logWARNING, - ("Power %d enabled, dac value %d, voltage at minimum or 0\n", ind, - LTC2620_D_GetPowerDownValue())); + LOG(logWARNING, ("Power V%s powered down\n", powerNames[pwrIndex])); return LTC2620_D_GetPowerDownValue(); } // get dac in mV - // (unless its a different voltage range compared to other dacs) - return getDAC(ind, 1); + int retval = -1; + ConvertToDifferentRange(LTC2620_D_GetMaxInput(), LTC2620_D_GetMinInput(), + POWER_RGLTR_MIN, POWER_RGLTR_MAX, dacValues[ind], + &retval); + + return retval; } void setPower(enum DACINDEX ind, int val) { + char *powerNames[] = {PWR_NAMES}; + int pwrIndex = (int)(ind - D_PWR_D); - uint32_t addr = CTRL_REG; - uint32_t offset = POWER_VCC_A_OFST + (int)(D_PWR_A - ind); - if (ind == D_PWR_IO) - offset = POWER_VIO_OFST; - uint32_t mask = (1 << offset); - - if (val >= 0 || val == LTC2620_D_GetPowerDownValue()) { - if (val > 0) { - LOG(logINFO, ("Setting Power to %d mV\n", val)); - } - - // switch off power enable - LOG(logINFO, ("\tSwitching off enable for P%d (ctrl reg)\n", - (int)(ind - D_PWR_A))); - bus_w(addr, bus_r(addr) | mask); - - // power down dac - LOG(logINFO, ("\tPowering down P%d\n", (int)(ind - D_PWR_A))); + // power down dac + if (val == LTC2620_D_GetPowerDownValue()) { + LOG(logINFO, ("\tPowering down V%d\n", powerNames[pwrIndex])); setDAC(ind, LTC2620_D_GetPowerDownValue(), 0); + } - // set dac in mV - if (val > 0) { - LOG(logINFO, ("\tSetting Power P%d (DAC %d) to %d mV\n", - (int)(ind - D_PWR_A), (int)ind, val)); - setDAC(ind, val, 1); + // set dac + else if (val >= 0) { + LOG(logINFO, + ("Setting Power V%s to %d mV\n", powerNames[pwrIndex], val)); + + // validate value (already checked at tcp (funcs.c)) + if (!isPowerValid(ind, val)) { + return; } - // switch on power enable - if (getDAC(ind, 1) == val || val == LTC2620_D_GetPowerDownValue()) { - LOG(logINFO, ("\tSwitching on enable for P%d (ctrl reg)\n", - (int)(ind - D_PWR_A))); - bus_w(addr, bus_r(addr) & ~mask); + // convert voltage to dac + int dacval = -1; + if (ConvertToDifferentRange( + POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_D_GetMaxInput(), + LTC2620_D_GetMinInput(), val, &dacval) == FAIL) { + LOG(logERROR, + ("\tCannot convert Power V%s to dac value. Invalid value of %d " + "mV. Is not between " + "%d and %d mV\n", + powerNames[pwrIndex], val, POWER_RGLTR_MIN, POWER_RGLTR_MAX)); + return; } + + // set and power on/ update dac + LOG(logINFO, ("Setting Power V%s: %d mV (%d dac)\n", + powerNames[pwrIndex], val, dacval)); + setDAC(ind, dacval, 0); } } @@ -1147,7 +1147,7 @@ int getSlowADC(int ichan, int *retval) { #ifndef VIRTUAL char fname[MAX_STR_LENGTH]; memset(fname, 0, MAX_STR_LENGTH); - sprintf(fname, SLOWADC_DRIVER_FILE_NAME, adcDeviceIndex, ichan); + sprintf(fname, SLOWADC_DRIVER_FILE_NAME, ichan); LOG(logDEBUG1, ("fname %s\n", fname)); if (readParameterFromFile(fname, "slow adc", retval) == FAIL) { diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h index 288275dbd..58926287c 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h @@ -25,15 +25,13 @@ #define DYNAMIC_RANGE (16) #define NUM_BYTES_PER_PIXEL (DYNAMIC_RANGE / 8) -#define DAC_DRIVER_NUM_DEVICES (3) -#define DAC_DRIVER_FILE_NAME \ - ("/sys/bus/iio/devices/iio:device%d/out_voltage%d_raw") +#define DAC_DRIVER_FILE_NAME ("/root/apps/xilinx-ctb/current_board_links/ao%d") #define DAC_POWERDOWN_DRIVER_FILE_NAME \ - ("/sys/bus/iio/devices/iio:device%d/out_voltage%d_powerdown") + ("/root/apps/xilinx-ctb/current_board_links/ao%d_pd") #define SLOWADC_DRIVER_FILE_NAME \ - ("/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw") -//#define SLOWDAC_CONVERTION_FACTOR_TO_UV (62.500953) + ("/root/apps/xilinx-ctb/mythenIII_0.2_1.1/links/ai%d") +// #define SLOWDAC_CONVERTION_FACTOR_TO_UV (62.500953) #define TEMP_DRIVER_FILE_NAME \ ("/sys/bus/iio/devices/iio:device0/in_temp7_input") @@ -60,8 +58,11 @@ #define MAX_ANALOG_SAMPLES (0x3FFF) #define MAX_DIGITAL_SAMPLES (0x3FFF) -#define DAC_MIN_MV (0) -#define DAC_MAX_MV (2500) +#define DAC_MIN_MV (0) +#define DAC_MAX_MV (2048) +#define POWER_RGLTR_MIN (1041) +#define POWER_RGLTR_MAX (2661) +#define VIO_MIN_MV (1200) // for fpga to function #define TICK_CLK (20) // MHz (trig_timeFromStart, frametime, timeFromStart) #define RUN_CLK \ @@ -117,28 +118,35 @@ enum DACINDEX { D_PWR_C }; +#define PWR_NAMES "D", "_unknown", "IO", "A", "B", "C" + /* Struct Definitions */ +// For arm has to be multiple of 16 +// We dont byteswap in the upd_gen so the order has to be different typedef struct udp_header_struct { - uint32_t udp_destmac_msb; uint16_t udp_srcmac_msb; uint16_t udp_destmac_lsb; - uint32_t udp_srcmac_lsb; + uint32_t udp_destmac_msb; uint8_t ip_tos; uint8_t ip_ihl : 4, ip_ver : 4; uint16_t udp_ethertype; - uint16_t ip_identification; - uint16_t ip_totallength; + uint32_t udp_srcmac_lsb; uint8_t ip_protocol; uint8_t ip_ttl; uint16_t ip_fragmentoffset : 13, ip_flags : 3; - uint16_t ip_srcip_msb; - uint16_t ip_checksum; + uint16_t ip_identification; + uint16_t ip_totallength; uint16_t ip_destip_msb; uint16_t ip_srcip_lsb; - uint16_t udp_srcport; - uint16_t ip_destip_lsb; + uint16_t ip_srcip_msb; + uint16_t ip_checksum; uint16_t udp_checksum; uint16_t udp_destport; + uint16_t udp_srcport; + uint16_t ip_destip_lsb; + // padding + uint32_t padding0; + uint32_t padding1; } udp_header; #define IP_HEADER_SIZE (20) diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 2ac36362e..fdc80a2d7 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -4,11 +4,11 @@ #define RELEASE "developer" #define APILIB "developer 0x230224" #define APIRECEIVER "developer 0x230224" -#define APICTB "developer 0x240725" -#define APIGOTTHARD "developer 0x240725" -#define APIJUNGFRAU "developer 0x240725" -#define APIMYTHEN3 "developer 0x240725" -#define APIMOENCH "developer 0x240725" -#define APIXILINXCTB "developer 0x240725" -#define APIEIGER "developer 0x240725" -#define APIGOTTHARD2 "developer 0x240731" +#define APICTB "developer 0x240820" +#define APIGOTTHARD "developer 0x240820" +#define APIGOTTHARD2 "developer 0x240820" +#define APIJUNGFRAU "developer 0x240820" +#define APIMYTHEN3 "developer 0x240820" +#define APIMOENCH "developer 0x240820" +#define APIEIGER "developer 0x240820" +#define APIXILINXCTB "developer 0x240820"