diff --git a/libs/pybind11 b/libs/pybind11 index 8de7772cc..4f72ef846 160000 --- a/libs/pybind11 +++ b/libs/pybind11 @@ -1 +1 @@ -Subproject commit 8de7772cc72daca8e947b79b83fea46214931604 +Subproject commit 4f72ef846fe8453596230ac285eeaa0ce3278bb4 diff --git a/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt b/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt index b9740a0fe..92c795bee 100644 --- a/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt +++ b/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(mythen3DetectorServer_virtual slsDetectorFunctionList.c + mythen3.c ../slsDetectorServer/src/slsDetectorServer.c ../slsDetectorServer/src/slsDetectorServer_funcs.c ../slsDetectorServer/src/communication_funcs.c @@ -10,7 +11,8 @@ add_executable(mythen3DetectorServer_virtual ../slsDetectorServer/src/LTC2620_Driver.c ../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c ../slsDetectorServer/src/programFpgaNios.c - ../slsDetectorServer/src/readDefaultPattern.c + ../slsDetectorServer/src/readDefaultPattern.c + ../slsDetectorServer/src/loadPattern.c ../slsDetectorServer/src/sharedMemory.c ) diff --git a/slsDetectorServers/mythen3DetectorServer/Makefile b/slsDetectorServers/mythen3DetectorServer/Makefile index 149cf15c6..abb2494c8 100755 --- a/slsDetectorServers/mythen3DetectorServer/Makefile +++ b/slsDetectorServers/mythen3DetectorServer/Makefile @@ -13,7 +13,7 @@ DESTDIR ?= bin INSTMODE = 0777 SRCS = slsDetectorFunctionList.c -SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c $(main_src)readDefaultPattern.c $(main_src)/sharedMemory.c +SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c $(main_src)readDefaultPattern.c $(main_src)/sharedMemory.c $(main_src)/loadPattern.c mythen3.c OBJS = $(SRCS:.c=.o) @@ -40,4 +40,4 @@ clean: rm -rf $(DESTDIR)/$(PROGS) *.o *.gdb $(main_src)*.o - \ No newline at end of file + diff --git a/slsDetectorServers/mythen3DetectorServer/mythen3.c b/slsDetectorServers/mythen3DetectorServer/mythen3.c new file mode 100644 index 000000000..fba996ad7 --- /dev/null +++ b/slsDetectorServers/mythen3DetectorServer/mythen3.c @@ -0,0 +1,276 @@ + +#include "clogger.h" +#include "common.h" +#include "mythen3.h" +#include "sls/ansi.h" +#include "sls/sls_detector_defs.h" +#include "slsDetectorServer_defs.h" + +#include + +/* +// Common C/C++ structure to handle pattern data +typedef struct __attribute__((packed)) { + uint64_t word[MAX_PATTERN_LENGTH]; + uint64_t ioctrl; + uint32_t limits[2]; + // loop0 start, loop0 stop .. loop2 start, loop2 stop + uint32_t loop[6]; + uint32_t nloop[3]; + uint32_t wait[3]; + uint64_t waittime[3]; +} patternParameters; +*/ + +int chipStatusRegister=0; + +int setBit(int ibit, int patword) { return patword |= (1 << ibit); } + +int clearBit(int ibit, int patword) { return patword &= ~(1 << ibit); } + +extern enum TLogLevel trimmingPrint ; + + +patternParameters *setChipStatusRegister(int csr) { + int iaddr=0; + int nbits=18; + int error=0; + //int start=0, stop=MAX_PATTERN_LENGTH, loop=0; + int patword=0; + + patternParameters *pat = malloc(sizeof(patternParameters)); + memset(pat, 0, sizeof(patternParameters)); + + patword=setBit(SIGNAL_STATLOAD,patword); + for (int i=0; i<2; i++) + pat->word[iaddr++]=patword; + patword=setBit(SIGNAL_resStorage,patword); + patword=setBit(SIGNAL_resCounter,patword); + for (int i=0; i<8; i++) + pat->word[iaddr++]=patword; + patword=clearBit(SIGNAL_resStorage,patword); + patword=clearBit(SIGNAL_resCounter,patword); + for (int i=0; i<8; i++) + pat->word[iaddr++]=patword; + //#This version of the serializer pushes in the MSB first (compatible with the CSR bit numbering) + for (int ib=nbits-1; ib>=0; ib--) { + if (csr&(1<word[iaddr++]=patword; + patword=setBit(SIGNAL_CHSclk,patword); + pat->word[iaddr++]=patword; + patword=clearBit(SIGNAL_CHSclk,patword); + pat->word[iaddr++]=patword; + } + + patword=clearBit(SIGNAL_serialIN,patword); + for (int i=0; i<2; i++) + pat->word[iaddr++]=patword; + patword=setBit(SIGNAL_STO,patword); + for (int i=0; i<5; i++) + pat->word[iaddr++]=patword; + patword=clearBit(SIGNAL_STO,patword); + for (int i=0; i<5; i++) + pat->word[iaddr++]=patword; + patword=clearBit(SIGNAL_STATLOAD,patword); + for (int i=0; i<5; i++) + pat->word[iaddr++]=patword; + + if (iaddr >= MAX_PATTERN_LENGTH) { + LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n", + iaddr, MAX_PATTERN_LENGTH)); + error = 1; + } + // set pattern wait address + for (int i = 0; i <= 2; i++) + pat->wait[i]=MAX_PATTERN_LENGTH - 1; + // pattern loop + for (int i = 0; i <= 2; i++) { + //int stop = MAX_PATTERN_LENGTH - 1, nloop = 0; + pat->loop[i * 2 + 0]=MAX_PATTERN_LENGTH - 1; + pat->loop[i * 2 + 1]=MAX_PATTERN_LENGTH - 1; + pat->nloop[i]=0; + } + + // pattern limits + { + pat->limits[0]=0; + pat->limits[1]=iaddr; + } + + if (error != 0) { + free(pat); + return NULL; + } + chipStatusRegister=csr; + return pat; + +} + +patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits) { + + patternParameters *pat = malloc(sizeof(patternParameters)); + memset(pat, 0, sizeof(patternParameters)); + + + // validate + for (int ichan = ichip * NCHAN_1_COUNTER * NCOUNTERS; ichan < ichip * NCHAN_1_COUNTER * NCOUNTERS+NCHAN_1_COUNTER*NCOUNTERS; ichan++) { + if (trimbits[ichan]<0) { + LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid - setting it to 0\n", + trimbits[ichan], ichan)); + trimbits[ichan]=0; + } + if (trimbits[ichan] > 63) { + LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid - settings it to 63\n", + trimbits[ichan], ichan)); + trimbits[ichan]=63; + } + } + LOG(logINFO, ("Trimbits validated\n")); + trimmingPrint = logDEBUG5; + + + // trimming + int error = 0; + uint64_t patword = 0; + int iaddr = 0; + + LOG(logDEBUG1, (" Chip %d\n", ichip)); + iaddr = 0; + patword = 0; + pat->word[iaddr++]=patword; + + // chip select + patword = setBit(SIGNAL_TBLoad_1 + ichip, patword); + pat->word[iaddr++]=patword; + + // reset trimbits + patword = setBit(SIGNAL_resStorage, patword); + patword = setBit(SIGNAL_resCounter, patword); + pat->word[iaddr++]=patword; + pat->word[iaddr++]=patword; + patword = clearBit(SIGNAL_resStorage, patword); + patword = clearBit(SIGNAL_resCounter, patword); + pat->word[iaddr++]=patword; + pat->word[iaddr++]=patword; + + // select first channel + patword = setBit(SIGNAL_CHSserialIN, patword); + pat->word[iaddr++]=patword; + // 1 clk pulse + patword = setBit(SIGNAL_CHSclk, patword); + pat->word[iaddr++]=patword; + patword = clearBit(SIGNAL_CHSclk, patword); + // clear 1st channel + pat->word[iaddr++]=patword; + patword = clearBit(SIGNAL_CHSserialIN, patword); + // 2 clk pulses + for (int i = 0; i < 2; i++) { + patword = setBit(SIGNAL_CHSclk, patword); + pat->word[iaddr++]=patword; + patword = clearBit(SIGNAL_CHSclk, patword); + pat->word[iaddr++]=patword; + } + + // for each channel (all chips) + for (int ich = 0; ich < NCHAN_1_COUNTER; ich++) { + LOG(logDEBUG1, (" Chip %d, Channel %d\n", ichip, ich)); + int val = trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + + NCOUNTERS * ich] + + trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + + NCOUNTERS * ich + 1] * + 64 + + trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + + NCOUNTERS * ich + 2] * + 64 * 64; + + // push 6 0 bits + for (int i = 0; i < 3; i++) { + patword = clearBit(SIGNAL_serialIN, patword); + patword = clearBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + patword = setBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + } + + for (int i = 0; i < 3; i++) { + if (mask[i]) + patword = setBit(SIGNAL_serialIN, patword); + else + patword = clearBit(SIGNAL_serialIN, patword); + patword = clearBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + patword = setBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + } + + // deserialize + for (int i = 0; i < 18; i++) { + if (val & (1 << i)) { + patword = setBit(SIGNAL_serialIN, patword); + } else { + patword = clearBit(SIGNAL_serialIN, patword); + } + patword = clearBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + + patword = setBit(SIGNAL_clk, patword); + pat->word[iaddr++]=patword; + } + pat->word[iaddr++]=patword; + pat->word[iaddr++]=patword; + + // move to next channel + for (int i = 0; i < 3; i++) { + patword = setBit(SIGNAL_CHSclk, patword); + pat->word[iaddr++]=patword; + patword = clearBit(SIGNAL_CHSclk, patword); + pat->word[iaddr++]=patword; + } + } + // chip unselect + patword = clearBit(SIGNAL_TBLoad_1 + ichip, patword); + pat->word[iaddr++]=patword; + + // last iaddr check + if (iaddr >= MAX_PATTERN_LENGTH) { + LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n", + iaddr, MAX_PATTERN_LENGTH)); + error = 1; + } + + if (iaddr >= MAX_PATTERN_LENGTH) { + LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n", + iaddr, MAX_PATTERN_LENGTH)); + error = 1; + } + // set pattern wait address + for (int i = 0; i <= 2; i++) + pat->wait[i]=MAX_PATTERN_LENGTH - 1; + // pattern loop + for (int i = 0; i <= 2; i++) { + //int stop = MAX_PATTERN_LENGTH - 1, nloop = 0; + pat->loop[i * 2 + 0]=MAX_PATTERN_LENGTH - 1; + pat->loop[i * 2 + 1]=MAX_PATTERN_LENGTH - 1; + pat->nloop[i]=0; + } + + // pattern limits + { + pat->limits[0]=0; + pat->limits[1]=iaddr; + } + + trimmingPrint = logINFO; + if (error == 0) { + + LOG(logINFO, ("All trimbits have been loaded\n")); + } else { + free(pat); + return NULL; + } + return pat; +} diff --git a/slsDetectorServers/mythen3DetectorServer/mythen3.h b/slsDetectorServers/mythen3DetectorServer/mythen3.h new file mode 100644 index 000000000..39ed5ce80 --- /dev/null +++ b/slsDetectorServers/mythen3DetectorServer/mythen3.h @@ -0,0 +1,59 @@ +#ifndef MYTHEN3_H +#define MYTHEN3_H + +#include "Pattern.h" + +/** Signal Definitions */ +#define SIGNAL_TBLoad_1 (0) +#define SIGNAL_TBLoad_2 (1) +#define SIGNAL_TBLoad_3 (2) +#define SIGNAL_TBLoad_4 (3) +#define SIGNAL_TBLoad_5 (4) +#define SIGNAL_TBLoad_6 (5) +#define SIGNAL_TBLoad_7 (6) +#define SIGNAL_TBLoad_8 (7) +#define SIGNAL_TBLoad_9 (8) +#define SIGNAL_TBLoad_10 (9) +#define SIGNAL_AnaMode (10) +#define SIGNAL_CHSserialIN (11) +#define SIGNAL_READOUT (12) +#define SIGNAL_pulse (13) +#define SIGNAL_EN1 (14) +#define SIGNAL_EN2 (15) +#define SIGNAL_EN3 (16) +#define SIGNAL_clk (17) +#define SIGNAL_SRmode (18) +#define SIGNAL_serialIN (19) +#define SIGNAL_STO (20) +#define SIGNAL_STATLOAD (21) +#define SIGNAL_resStorage (22) +#define SIGNAL_resCounter (23) +#define SIGNAL_CHSclk (24) +#define SIGNAL_exposing (25) + + +//CHIP STARTUS REGISTER BITS +#define CSR_spypads 0 +#define CSR_invpol 4 +#define CSR_dpulse 5 +#define CSR_interp 6 +#define CSR_C10pre 7 //#default +#define CSR_pumprobe 8 +#define CSR_apulse 9 +#define CSR_C15sh 10 +#define CSR_C30sh 11 //#default +#define CSR_C50sh 12 +#define CSR_C225ACsh 13 // Connects 225fF SHAPER AC cap (1: 225 to shaper, 225 to GND. 0: 450 to shaper) +#define CSR_C15pre 14 + +#define CSR_default (1< #endif -/// NOT the right place to put it! -int setChipStatusRegister(int csr); // Global variable from slsDetectorServer_funcs extern int debugflag; @@ -47,11 +47,12 @@ enum detectorSettings thisSettings; sls_detector_module *detectorModules = NULL; int *detectorChans = NULL; int *detectorDacs = NULL; +int *channelMask=NULL; -enum TLogLevel trimmingPrint = logINFO; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkDivider[NUM_CLOCKS] = {}; +enum TLogLevel trimmingPrint = logINFO; int highvoltage = 0; int detPos[2] = {}; int64_t exptimeReg[NCOUNTERS] = {0, 0, 0}; @@ -374,7 +375,11 @@ void allocateDetectorStructureMemory() { // Allocation of memory detectorModules = malloc(sizeof(sls_detector_module)); detectorChans = malloc(NCHIP * NCHAN * sizeof(int)); + channelMask = malloc(NCHIP * NCHAN * sizeof(char)); + memset(channelMask, 0, NCHIP * NCHAN * sizeof(char)); detectorDacs = malloc(NDAC * sizeof(int)); + + LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n", detectorModules, detectorModules)); LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans)); @@ -513,9 +518,12 @@ void setupDetector() { powerChip(1); if (initError != FAIL) { - initError = setChipStatusRegister(CSR_default); - //loadDefaultPattern(DEFAULT_PATTERN_FILE, initErrorMessage); - //startStateMachine(); //this was missing in previous code! runs the default pattern + patternParameters *pat=setChipStatusRegister(CSR_default); + if (pat) { + initError=loadPattern(pat); + startStateMachine(); + free(pat); + } } setAllTrimbits(DEFAULT_TRIMBIT_VALUE); } @@ -1136,161 +1144,38 @@ int setModule(sls_detector_module myMod, char *mess) { return OK; } -int setBit(int ibit, int patword) { return patword |= (1 << ibit); } - -int clearBit(int ibit, int patword) { return patword &= ~(1 << ibit); } - int setTrimbits(int *trimbits) { - LOG(logINFOBLUE, ("Setting trimbits\n")); - - // validate - for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) { - if (trimbits[ichan] < 0 || trimbits[ichan] > 63) { - LOG(logERROR, ("Trimbit value (%d) for channel %d is invalid\n", - trimbits[ichan], ichan)); - return FAIL; - } - } - LOG(logINFO, ("Trimbits validated\n")); - trimmingPrint = logDEBUG5; + // remember previous run clock uint32_t prevRunClk = clkDivider[SYSTEM_C0]; - + patternParameters *pat=NULL; + int error=0; // set to trimming clock if (setClockDivider(SYSTEM_C0, DEFAULT_TRIMMING_RUN_CLKDIV) == FAIL) { LOG(logERROR, ("Could not start trimming. Could not set to trimming clock\n")); return FAIL; } + ///////////////////////////////////////////////////////////////// + for (int ichip=0; ichip= MAX_PATTERN_LENGTH) { - LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n", - iaddr, MAX_PATTERN_LENGTH)); - error = 1; - break; - } - - // set pattern wait address - for (int i = 0; i <= 2; i++) - setPatternWaitAddress(i, MAX_PATTERN_LENGTH - 1); - - // pattern loop - for (int i = 0; i <= 2; i++) { - int stop = MAX_PATTERN_LENGTH - 1, nloop = 0; - setPatternLoop(i, &stop, &stop, &nloop); - } - - // pattern limits - { - int start = 0, nloop = 0; - setPatternLoop(-1, &start, &iaddr, &nloop); - } - // send pattern to the chips - startPattern(); + pat=setChannelRegisterChip(ichip,channelMask,trimbits); //change here!!! + if (pat) { + error|=loadPattern(pat); + if (error==0) + startPattern(); + free(pat); + } else + error=1; } - + ///////////////////////////////////////////////////////////////// if (error == 0) { - // copy trimbits locally - for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) { - detectorChans[ichan] = trimbits[ichan]; - } - LOG(logINFO, ("All trimbits have been loaded\n")); + // copy trimbits locally + for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) { + detectorChans[ichan] = trimbits[ichan]; + } + LOG(logINFO, ("All trimbits have been loaded\n")); } trimmingPrint = logINFO; @@ -2779,77 +2664,3 @@ int getNumberOfChips() { return NCHIP; } int getNumberOfDACs() { return NDAC; } int getNumberOfChannelsPerChip() { return NCHAN; } -int setChipStatusRegister(int csr) { - int iaddr=0; - int nbits=18; - int error=0; - //int start=0, stop=MAX_PATTERN_LENGTH, loop=0; - int patword=0; - patword=setBit(SIGNAL_STATLOAD,patword); - for (int i=0; i<2; i++) - writePatternWord(iaddr++, patword); - patword=setBit(SIGNAL_resStorage,patword); - patword=setBit(SIGNAL_resCounter,patword); - for (int i=0; i<8; i++) - writePatternWord(iaddr++, patword); - patword=clearBit(SIGNAL_resStorage,patword); - patword=clearBit(SIGNAL_resCounter,patword); - for (int i=0; i<8; i++) - writePatternWord(iaddr++, patword); - //#This version of the serializer pushes in the MSB first (compatible with the CSR bit numbering) - for (int ib=nbits-1; ib>=0; ib--) { - if (csr&(1<= MAX_PATTERN_LENGTH) { - LOG(logERROR, ("Addr 0x%x is past max_address_length 0x%x!\n", - iaddr, MAX_PATTERN_LENGTH)); - error = 1; - } - // set pattern wait address - for (int i = 0; i <= 2; i++) - setPatternWaitAddress(i, MAX_PATTERN_LENGTH - 1); - - // pattern loop - for (int i = 0; i <= 2; i++) { - int stop = MAX_PATTERN_LENGTH - 1, nloop = 0; - setPatternLoop(i, &stop, &stop, &nloop); - } - - // pattern limits - { - int start = 0, nloop = 0; - setPatternLoop(-1, &start, &iaddr, &nloop); - } - // send pattern to the chips - startPattern(); - - if (error != 0) { - return FAIL; - } - - return OK; - -} diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 556b69e45..e00e458d9 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -158,47 +158,3 @@ typedef struct udp_header_struct { #define UDP_IP_HEADER_LENGTH_BYTES (28) #define PACKETS_PER_FRAME_10G (2) #define PACKETS_PER_FRAME_1G (20) - -/** Signal Definitions */ -#define SIGNAL_TBLoad_1 (0) -#define SIGNAL_TBLoad_2 (1) -#define SIGNAL_TBLoad_3 (2) -#define SIGNAL_TBLoad_4 (3) -#define SIGNAL_TBLoad_5 (4) -#define SIGNAL_TBLoad_6 (5) -#define SIGNAL_TBLoad_7 (6) -#define SIGNAL_TBLoad_8 (7) -#define SIGNAL_TBLoad_9 (8) -#define SIGNAL_TBLoad_10 (9) -#define SIGNAL_AnaMode (10) -#define SIGNAL_CHSserialIN (11) -#define SIGNAL_READOUT (12) -#define SIGNAL_pulse (13) -#define SIGNAL_EN1 (14) -#define SIGNAL_EN2 (15) -#define SIGNAL_EN3 (16) -#define SIGNAL_clk (17) -#define SIGNAL_SRmode (18) -#define SIGNAL_serialIN (19) -#define SIGNAL_STO (20) -#define SIGNAL_STATLOAD (21) -#define SIGNAL_resStorage (22) -#define SIGNAL_resCounter (23) -#define SIGNAL_CHSclk (24) -#define SIGNAL_exposing (25) - -//CHIP STARTUS REGISTER BITS -#define CSR_spypads 0 -#define CSR_invpol 4 -#define CSR_dpulse 5 -#define CSR_interp 6 -#define CSR_C10pre 7 //#default -#define CSR_pumprobe 8 -#define CSR_apulse 9 -#define CSR_C15sh 10 -#define CSR_C30sh 11 //#default -#define CSR_C50sh 12 -#define CSR_C225ACsh 13 // Connects 225fF SHAPER AC cap (1: 225 to shaper, 225 to GND. 0: 450 to shaper) -#define CSR_C15pre 14 - -#define CSR_default (1< +#include + +extern char initErrorMessage[MAX_STR_LENGTH]; + +#ifndef MYTHEN3D +extern uint64_t writePatternIOControl(uint64_t word); +#endif +extern uint64_t writePatternWord(int addr, uint64_t word); +extern int setPatternWaitAddress(int level, int addr); +extern uint64_t setPatternWaitTime(int level, uint64_t t); +extern void setPatternLoop(int level, int *startAddr, int *stopAddr, + int *nLoop); + +int loadPattern(patternParameters *pat) { + + int ret=OK; + + for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) { + if ((i % 10 == 0) && pat->word[i] != 0) { + LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", + i, (long long int)pat->word[i])); + } + writePatternWord(i, pat->word[i]); + } +#ifndef MYTHEN3D + if (ret == OK) { + uint64_t retval64 = writePatternIOControl(pat->ioctrl); + //validate64(pat->ioctrl, retval64, "set pattern IO Control", HEX); + } +#endif + if (ret == OK) { + int numLoops = -1; + int retval0 = pat->limits[0]; + int retval1 = pat->limits[1]; + setPatternLoop(-1, &retval0, &retval1, &numLoops); + //validate(pat->limits[0], retval0, + // "set pattern Limits start address", HEX); + //validate(pat->limits[1], retval1, + // "set pattern Limits start address", HEX); + } + uint64_t retval64; + if (ret == OK) { + for (int i = 0; i <= 2; ++i) { + char msg[128]; + int retval0 = -1, retval1 = -1, numLoops = -1; + + // patloop + retval0 = pat->loop[i * 2 + 0]; + retval1 = pat->loop[i * 2 + 1]; + numLoops = pat->nloop[i]; + setPatternLoop(i, &retval0, &retval1, &numLoops); + memset(msg, 0, sizeof(msg)); + sprintf(msg, "set pattern Loop %d start address", i); + //validate(pat->loop[i * 2 + 0], retval0, msg, HEX); + if (ret == FAIL) { + break; + } + memset(msg, 0, sizeof(msg)); + sprintf(msg, "set pattern Loop %d stop address", i); + //validate(pat->loop[i * 2 + 1], retval1, msg, HEX); + if (ret == FAIL) { + break; + } + memset(msg, 0, sizeof(msg)); + sprintf(msg, "set pattern Loop %d num loops", i); + //validate(pat->nloop[i], numLoops, msg, HEX); + if (ret == FAIL) { + break; + } + // patwait + memset(msg, 0, sizeof(msg)); + sprintf(msg, "set pattern Loop %d wait address", i); + retval0 = setPatternWaitAddress(i, pat->wait[i]); + //validate(pat->wait[i], retval0, msg, HEX); + if (ret == FAIL) { + break; + } + + // patwaittime + memset(msg, 0, sizeof(msg)); + sprintf(msg, "set pattern Loop %d wait time", i); + retval64 = setPatternWaitTime(i, pat->waittime[i]); + //validate64(pat->waittime[i], retval64, msg, HEX); + if (retval64 == FAIL) { + break; + } + } + } + return ret; +} + + diff --git a/slsDetectorServers/slsDetectorServer/src/readDefaultPattern.c b/slsDetectorServers/slsDetectorServer/src/readDefaultPattern.c index ab731062a..d4473be4d 100644 --- a/slsDetectorServers/slsDetectorServer/src/readDefaultPattern.c +++ b/slsDetectorServers/slsDetectorServer/src/readDefaultPattern.c @@ -1,4 +1,5 @@ #include "readDefaultPattern.h" +#include "loadPattern.h" #include "clogger.h" #include "common.h" #include "sls/ansi.h" diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 09da78b48..7c3b50f79 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -7578,18 +7578,22 @@ int set_pattern(int file_des) { patternParameters *pat = malloc(sizeof(patternParameters)); memset(pat, 0, sizeof(patternParameters)); - - // ignoring endianness for eiger + // ignoring endianness for eiger if (receiveData(file_des, pat, sizeof(patternParameters), INT32) < 0) { if (pat != NULL) free(pat); return printSocketReadError(); } - + if (Server_VerifyLock() == OK) { LOG(logINFO, ("Setting Pattern from structure\n")); LOG(logINFO, - ("Setting Pattern Word (printing every 10 words that are not 0\n")); + ("Setting Pattern Word (printing every 10 words that are not 0\n")); + /****************************************************************************************************************/ + /* I SUGGEST TO VALIDATE THE VALUES HERE AND THEN WRITE THE PATTERN IN A SEPARATE FUNCTION WHICH COULD BE REUSED*/ + /* added loadPattern.c/h - the same func could be reused also in readDefaultPattern */ + /***************************************************************************************************************/ + for (int i = 0; i < MAX_PATTERN_LENGTH; ++i) { if ((i % 10 == 0) && pat->word[i] != 0) { LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", @@ -7662,6 +7666,7 @@ int set_pattern(int file_des) { } } } + /******* DOWN TO HERE ***********/ } if (pat != NULL) free(pat);