diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml index 459a64a2f..a7fd764c4 100644 --- a/.github/workflows/build_documentation.yml +++ b/.github/workflows/build_documentation.yml @@ -6,6 +6,10 @@ on: branches: - developer - main + push: + branches: + - developer + - main release: types: - published @@ -87,7 +91,7 @@ jobs: - name: Copy documentation and Release notes to versioned folder - if: github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + if: github.event_name == 'release' || (github.event_name == 'push') run: | VERSION="${{ steps.version.outputs.version }}" mkdir -p "gh-pages/${VERSION}" @@ -99,7 +103,7 @@ jobs: fi - name: Commit and Push changes to gh-pages - if: github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + if: github.event_name == 'release' || (github.event_name == 'push') run: | cd gh-pages git config --global user.name 'github-actions' diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index dde4a9e3c..eeed02b79 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -517,13 +517,12 @@ class Detector(CppDetectorApi): @element def powerchip(self): """ - [Jungfrau][Moench][Mythen3][Gotthard2][Xilinx Ctb][Ctb] Power the chip. + [Jungfrau][Moench][Mythen3][Gotthard2] Power the chip. Note ---- [Jungfrau][Moench] Default is disabled. Get will return power status. Can be off if temperature event occured (temperature over temp_threshold with temp_control enabled. Will configure chip (only chip v1.1).\n [Mythen3][Gotthard2] Default is 1. If module not connected or wrong module, powerchip will fail. - [Xilinx Ctb] Default is 0. Also configures the chip if powered on. """ return self.getPowerChip() diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index a2370acc2..07c0556cd 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 3a9a352c3..341a05272 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -529,7 +529,7 @@ void setupDetector() { for (int i = 0; i != NDAC_ONLY; ++i) dacValues[i] = -1; for (int i = 0; i != NPWR; ++i) - powerValues[i] = -1; + powerValues[i] = 0; // to calculate vchip } vLimit = DEFAULT_VLIMIT; highvoltage = 0; @@ -1496,6 +1496,23 @@ int setPowerDAC(enum powerIndex ind, int voltage, char *mess) { if (validatePower(ind, voltage, mess) == FAIL) return FAIL; + // to be values + bool pwrEnables[NPWR - 1] = {0}; + int pwrValues[NPWR - 1] = {0}; + if (getAllPowerValues(pwrEnables, pwrValues, mess) == FAIL) + return FAIL; + // update with current command + pwrValues[ind] = voltage; + + // set vchip accordingly + { + int vchip = 0; + if (computeVchip(&vchip, pwrEnables, pwrValues, mess) == FAIL) + return FAIL; + if (setVchip(vchip, mess) == FAIL) + return FAIL; + } + int dacval = -1; if (convertVoltageToPowerDAC(ind, voltage, &dacval, mess) == FAIL) return FAIL; @@ -1585,20 +1602,33 @@ int setPowerEnabled(enum powerIndex indices[], int count, bool enable, { char *powerNames[] = {PWR_NAMES}; char message[256] = {0}; - sprintf(message, "Switching %s power for ", enable ? "on" : "off"); + sprintf(message, "Switching %s power for [", enable ? "on" : "off"); for (int i = 0; i != count; ++i) { strcat(message, powerNames[indices[i]]); + strcat(message, ", "); } - strcat(message, "\n"); + strcat(message, "]\n"); LOG(logINFO, ("%s", message)); } + // to be values + bool pwrEnables[NPWR - 1] = {0}; + int pwrValues[NPWR - 1] = {0}; + if (getAllPowerValues(pwrEnables, pwrValues, mess) == FAIL) + return FAIL; + // update with current command + for (int i = 0; i != count; ++i) { + pwrEnables[indices[i]] = enable; + } + // set vchip accordingly - int vchipToSet = 0; - if (getVchipToSet(&vchipToSet, mess) == FAIL) - return FAIL; - if (setVchip(vchipToSet, mess) == FAIL) - return FAIL; + { + int vchip = 0; + if (computeVchip(&vchip, pwrEnables, pwrValues, mess) == FAIL) + return FAIL; + if (setVchip(vchip, mess) == FAIL) + return FAIL; + } // enable/disable power rails uint32_t addr = POWER_REG; @@ -1688,15 +1718,25 @@ int setVchip(int voltage, char *mess) { return OK; } -int getVchipToSet(int *retval_vchip, char *mess) { +int getAllPowerValues(bool *pwrEnables, int *pwrValues, char *mess) { + for (int ipwr = 0; ipwr != (NPWR - 1); ++ipwr) { + if (isPowerEnabled((enum powerIndex)ipwr, &pwrEnables[ipwr], mess) == + FAIL) + return FAIL; + if (getPowerDAC((enum powerIndex)ipwr, &pwrValues[ipwr], mess) == FAIL) + return FAIL; + } + return OK; +} + +int computeVchip(int *retval_vchip, bool *pwrEnables, int *pwrValues, + char *mess) { // get the max of all the power regulators int max = 0; - enum powerIndex pwrDacs[] = {V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, - V_POWER_IO}; for (int ipwr = 0; ipwr != 5; ++ipwr) { int val = 0; - if (getPowerDAC(pwrDacs[ipwr], &val, mess) == FAIL) - return FAIL; + if (pwrEnables[ipwr]) + val = pwrValues[ipwr]; if (val > max) max = val; } diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h index ed210916b..3dccdf8c1 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.h @@ -160,7 +160,12 @@ int isPowerEnabled(enum powerIndex ind, bool *retval, char *mess); int validateVchip(int val, char *mess); int getVchip(int *retval, char *mess); int setVchip(int val, char *mess); -int getVchipToSet(int *retval_vchip, char *mess); +int getAllPowerValues(bool *pwrEnable, int *pwrValues, char *mess); +/** pwrEnable and pwrValues are current values + * updated with the current command + * (current cmd: eg. power enable all or only set one power dac) */ +int computeVchip(int *retval_vchip, bool *pwrEnable, int *pwrValues, + char *mess); int getPowerADC(enum powerIndex index, int *retval, char *mess); diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 6bfcff974..21c2be1a2 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 0086d8737..e00d36522 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index e9d362f54..116598760 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 5f7877f33..7b7a4c34b 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 42dcef1d9..6a94723aa 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/slsDetectorServer/include/blackfin.h b/slsDetectorServers/slsDetectorServer/include/blackfin.h index 672f58c57..f08bd1b1b 100644 --- a/slsDetectorServers/slsDetectorServer/include/blackfin.h +++ b/slsDetectorServers/slsDetectorServer/include/blackfin.h @@ -122,3 +122,6 @@ uint32_t *Blackfin_getBaseAddress(); * Map FPGA */ int mapCSP0(void); + +/** sleep for only usecs */ +void usleep_bf(uint64_t i); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 67a091bbc..ea45b682e 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -6,8 +6,8 @@ #include "sls/sls_detector_defs.h" #include -#define GOODBYE (-200) -#define REBOOT (-400) +#define GOODBYE (-200) +#define REBOOT (-400) #define BFIN_SPI_WAIT_uSECONDS 25 // initialization functions diff --git a/slsDetectorServers/slsDetectorServer/src/blackfin.c b/slsDetectorServers/slsDetectorServer/src/blackfin.c index 06322de6d..eb70d3164 100644 --- a/slsDetectorServers/slsDetectorServer/src/blackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/blackfin.c @@ -11,12 +11,13 @@ #include // mmap /* global variables */ +const uint64_t BFIN_CYCLES_1uSECOND = 20; u_int32_t *csp0base = 0; + #define CSP0 0x20200000 #define MEM_SIZE 0x100000 #ifdef JUNGFRAUD - extern void configureChip(); #endif @@ -131,3 +132,11 @@ int mapCSP0(void) { } uint32_t *Blackfin_getBaseAddress() { return csp0base; } + +// usleep is not viable on blackfin +void usleep_bf(uint64_t i) { + uint64_t j = i * BFIN_CYCLES_1uSECOND; + while (--j) { + asm volatile(""); + } +} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index da87e3f6d..755f78104 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -10907,15 +10907,6 @@ int set_pattern_wait_interval(int file_des) { return Server_SendResult(file_des, INT64, NULL, 0); } -// usleep is not viable on blackfin -void usleep_bf(uint64_t i) { - const uint64_t BFIN_CYCLES_1uSECOND = 20; - uint64_t j = i * BFIN_CYCLES_1uSECOND; - while (--j) { - asm volatile(""); - } -} - /** * Non destructive read from SPI register. Read n_bytes by shifting in dummy * data while keeping csn 0 after the operation. Shift the read out data back @@ -11066,9 +11057,11 @@ int spi_read(int file_des) { #elif defined(CHIPTESTBOARDD) // set spi to 8 bit per word (-1 comes from the firmware), set chipselect bus_w(SPI_CTRL_REG, + ((8 - 1) << SPI_CTRL_NBIT_OFST) + (1 << SPI_CTRL_CHIPSELECT_BIT)); for (int i = 0; i < n_bytes + 1; ++i) { // TODO: should we make bus_w to this address blocking in the firmware + // // to remove usleep ? bus_w(SPI_WRITEDATA_REG, local_tx[i]); usleep_bf(BFIN_SPI_WAIT_uSECONDS); diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer index 4cf4a345b..bbceb193a 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 53db9e3dd..625dbabd0 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -382,9 +382,9 @@ void setupDetector() { analogEnable = 0; digitalEnable = 0; transceiverEnable = 0; - for (int i = 0; i != NDAC; ++i) + for (int i = 0; i != NDAC_ONLY; ++i) dacValues[i] = -1; - for (int i = 0; i != 5; ++i) + for (int i = 0; i != NPWR - 1; ++i) powerValues[i] = -1; vLimit = DEFAULT_VLIMIT; @@ -1170,11 +1170,12 @@ int setPowerEnabled(enum powerIndex indices[], int count, bool enable, { char *powerNames[] = {PWR_NAMES}; char message[256] = {0}; - sprintf(message, "Switching %s power for ", enable ? "on" : "off"); + sprintf(message, "Switching %s power for [", enable ? "on" : "off"); for (int i = 0; i != count; ++i) { strcat(message, powerNames[indices[i]]); + strcat(message, ", "); } - strcat(message, "\n"); + strcat(message, "]\n"); LOG(logINFO, ("%s", message)); } // enable/disable power rails diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 124347e8e..a44a46e5f 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -484,7 +484,6 @@ class Detector { * temp_control enabled. Will configure chip (only chip v1.1)\n * [Mythen3][Gotthard2] Default is 1. If module not connected or wrong * module, powerchip will fail.\n - * [Xilinx CTB] Default is 0. Also configures chip if powered on. */ void setPowerChip(bool on, Positions pos = {}); diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index fe9ee13fd..71c64048f 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -706,12 +706,102 @@ TEST_CASE("powerdac", "[.detectorintegration][dacs]") { REQUIRE(oss2.str() == "powerdac " + names[iPower] + " 1200\n"); } - // Reset all dacs to previous value det.setPowerDAC(indices[iPower], prev_val); det.setPowerEnabled(std::vector{indices[iPower]}, prev_val_power); } + // all + { + int prev_val[5] = {0}; + int prev_power_val[5] = {0}; + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + prev_val[iPower] = det.getPowerDAC(indices[iPower]); + prev_power_val[iPower] = + det.isPowerEnabled(indices[iPower]); + } + + // all off + REQUIRE_NOTHROW(caller.call("power", {"all", "off"}, -1, PUT)); + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + REQUIRE(det.isPowerEnabled(indices[iPower]) == false); + } + + // all on + REQUIRE_NOTHROW(caller.call("power", {"all", "on"}, -1, PUT)); + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + REQUIRE(det.isPowerEnabled(indices[iPower]) == true); + } + + // all off + REQUIRE_NOTHROW(caller.call("power", {"all", "off"}, -1, PUT)); + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + REQUIRE(det.isPowerEnabled(indices[iPower]) == false); + } + + // reset it to previous value + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + det.setPowerDAC(indices[iPower], prev_val[iPower]); + det.setPowerEnabled({indices[iPower]}, + prev_power_val[iPower]); + } + } + // vchip val + if (det_type == defs::CHIPTESTBOARD) { + const int min_vchip_val = 1673; + int prev_val[5] = {0}; + int prev_power_val[5] = {0}; + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + prev_val[iPower] = det.getPowerDAC(indices[iPower]); + prev_power_val[iPower] = + det.isPowerEnabled(indices[iPower]); + } + + // all off, vchip = min + REQUIRE_NOTHROW(caller.call("power", {"all", "off"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == min_vchip_val); + + // change dacs + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_a", "1500"}, -1, PUT)); + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_b", "1200"}, -1, PUT)); + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_c", "1200"}, -1, PUT)); + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_d", "1200"}, -1, PUT)); + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_io", "1200"}, -1, PUT)); + // vchip = min + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == min_vchip_val); + + // all on, vchip changes + REQUIRE_NOTHROW(caller.call("power", {"all", "on"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == 1700); + + // change dac, vchip changes to max + 200 + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_a", "1700"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == 1900); + REQUIRE_NOTHROW( + caller.call("powerdac", {"v_b", "1500"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == 1900); + + // switch off v_a, vchip = max + 200 of those enabled + REQUIRE_NOTHROW(caller.call("power", {"v_a", "off"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == 1700); + + // all off, vchip = min + REQUIRE_NOTHROW(caller.call("power", {"all", "off"}, -1, PUT)); + REQUIRE(det.getPowerDAC(defs::V_POWER_CHIP) == min_vchip_val); + + // reset it to previous value + for (size_t iPower = 0; iPower < names.size(); ++iPower) { + det.setPowerDAC(indices[iPower], prev_val[iPower]); + det.setPowerEnabled({indices[iPower]}, + prev_power_val[iPower]); + } + } } } else { diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index f74e29f7c..192e7f8f0 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -3,11 +3,11 @@ /** API versions */ #define APILIB "0.0.0 0x250909" #define APIRECEIVER "0.0.0 0x250822" -#define APICTB "0.0.0 0x260317" -#define APIGOTTHARD2 "0.0.0 0x260227" -#define APIMOENCH "0.0.0 0x260227" -#define APIEIGER "0.0.0 0x260227" -#define APIXILINXCTB "0.0.0 0x260324" -#define APIJUNGFRAU "0.0.0 0x260227" -#define APIMYTHEN3 "0.0.0 0x260227" +#define APICTB "0.0.0 0x260421" +#define APIGOTTHARD2 "0.0.0 0x260420" +#define APIMOENCH "0.0.0 0x260420" +#define APIEIGER "0.0.0 0x260420" +#define APIXILINXCTB "0.0.0 0x260420" +#define APIJUNGFRAU "0.0.0 0x260420" +#define APIMYTHEN3 "0.0.0 0x260420" #define APIMATTERHORN "0.0.0 0x260212" \ No newline at end of file