ctb & moench: phase fix for absolute within limits, option to set as degrees and get max phase shift, bug fix for eiger with implementation of 2 udp interface

This commit is contained in:
2019-03-27 12:25:38 +01:00
parent c7ad548e4c
commit c7c52c63cd
20 changed files with 667 additions and 454 deletions

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 7cd5bc8b2db6e89fbec4c06c65e683cf788338c0 Repsitory UUID: c7ad548e4c2026a826b9f269f32d9970ce0a44e8
Revision: 46 Revision: 48
Branch: jungfrau Branch: refactor
Last Changed Author: Dhanya_Thattil Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4474 Last Changed Rev: 4478
Last Changed Date: 2019-03-26 15:01:04.000000002 +0100 ./slsDetectorServer_defs.h Last Changed Date: 2019-03-27 11:13:21.000000002 +0100 ../slsDetectorServer/slsDetectorServer_funcs.c

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "7cd5bc8b2db6e89fbec4c06c65e683cf788338c0" #define GITREPUUID "c7ad548e4c2026a826b9f269f32d9970ce0a44e8"
#define GITAUTH "Dhanya_Thattil" #define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4474 #define GITREV 0x4478
#define GITDATE 0x20190326 #define GITDATE 0x20190327
#define GITBRANCH "jungfrau" #define GITBRANCH "refactor"

View File

@ -781,16 +781,15 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret) {
/* parameters - speed, readout */ /* parameters - speed, readout */
void setSpeed(enum speedVariable ind, int val) { void setSpeed(enum speedVariable ind, int val, int mode) {
switch(ind) { switch(ind) {
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT:
FILE_LOG(logINFOBLUE, ("Configuring ADC Phase\n")); FILE_LOG(logINFOBLUE, ("Configuring ADC Phase\n"));
configurePhase(ADC_CLK, val); configurePhase(ADC_CLK, val, mode);
break; break;
case DBIT_PHASE: case DBIT_PHASE:
FILE_LOG(logINFOBLUE, ("Configuring Dbit Phase\n")); FILE_LOG(logINFOBLUE, ("Configuring Dbit Phase\n"));
configurePhase(DBIT_CLK, val); configurePhase(DBIT_CLK, val, mode);
break; break;
case ADC_CLOCK: case ADC_CLOCK:
FILE_LOG(logINFOBLUE, ("Configuring ADC Clock\n")); FILE_LOG(logINFOBLUE, ("Configuring ADC Clock\n"));
@ -818,23 +817,26 @@ void setSpeed(enum speedVariable ind, int val) {
} }
} }
int getSpeed(enum speedVariable ind) { int getSpeed(enum speedVariable ind, int mode) {
switch(ind) { switch(ind) {
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT: return getPhase(ADC_CLK, mode);
return getPhase(ADC_CLK);
case DBIT_PHASE: case DBIT_PHASE:
return getPhase(DBIT_CLK); return getPhase(DBIT_CLK, mode);
case MAX_ADC_PHASE_SHIFT:
return getMaxPhase(ADC_CLK);
case MAX_DBIT_PHASE_SHIFT:
return getMaxPhase(DBIT_CLK);
case ADC_CLOCK: case ADC_CLOCK:
return getFrequency(ADC_CLK); return getFrequency(ADC_CLK);
case DBIT_CLOCK: case DBIT_CLOCK:
return getFrequency(DBIT_CLK); return getFrequency(DBIT_CLK);
case CLOCK_DIVIDER:
return getFrequency(RUN_CLK);
case ADC_PIPELINE: case ADC_PIPELINE:
return getAdcOffsetRegister(1); return getAdcOffsetRegister(1);
case DBIT_PIPELINE: case DBIT_PIPELINE:
return getAdcOffsetRegister(0); return getAdcOffsetRegister(0);
case CLOCK_DIVIDER:
return getFrequency(RUN_CLK);
default: default:
return -1; return -1;
} }
@ -1633,41 +1635,100 @@ int enableTenGigabitEthernet(int val) {
// ind can only be ADC_CLK or DBIT_CLK // ind can only be ADC_CLK or DBIT_CLK
void configurePhase(enum CLKINDEX ind, int val) { void configurePhase(enum CLKINDEX ind, int val, int degrees) {
char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"}; char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"};
if (val > 65535 || val < -65535) { int maxShift = getMaxPhase(ind);
FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits\n", ind, clock_names[ind]));
return; // validation
} if (degrees && (val < 0 || val > 359)) {
int relativePhase = clkPhase[ind] - val; FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits (0 - 359°C)\n", ind, clock_names[ind]));
return;
}
if (!degrees && (val < 0 || val > maxShift - 1)) {
FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits (0 - %d phase shifts)\n", ind, clock_names[ind], maxShift - 1));
return;
}
FILE_LOG(logINFO, ("Configuring Phase of C%d(%s) to %d (degree mode: %d)\n", ind, clock_names[ind], val, degrees));
int valShift = val;
// convert to phase shift
if (degrees) {
double temp = val * ((double)maxShift / 360.00);
if ((temp - (int)temp) > 0.0001) {
temp += 0.5;
}
valShift = temp;
FILE_LOG(logDEBUG1, ("phase shift: %d\n", valShift));
}
FILE_LOG(logDEBUG1, ("phase shift: %d (degrees/shift: %d)\n", valShift, val));
int relativePhase = clkPhase[ind] - valShift;
FILE_LOG(logDEBUG1, ("relative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
// same phase // same phase
if (!relativePhase) { if (!relativePhase) {
FILE_LOG(logDEBUG1, ("Nothing to do\n"));
return; return;
} }
FILE_LOG(logINFO, ("Configuring Phase of C%d(%s) to %d\n", ind, clock_names[ind], val));
int phase = 0; int phase = 0;
int maxShifts = (PLL_VCO_FREQ_MHZ / clkDivider[ind]) * MAX_PHASE_SHIFTS_STEPS;
FILE_LOG(logDEBUG1, ("Clock: %d MHz, VCO:%d MHz, Max Phase shifts:%d\n",
clkDivider[ind], PLL_VCO_FREQ_MHZ, maxShifts));
// delay clk
if (relativePhase > 0) { if (relativePhase > 0) {
phase = (maxShifts - relativePhase); phase = (maxShift - relativePhase);
} else { } else {
phase = (-1) * relativePhase; phase = (-1) * relativePhase;
} }
FILE_LOG(logINFO, ("\tphase out %d (0x%08x)\n", phase, phase)); FILE_LOG(logDEBUG1, ("[Single Direction] Phase:%d (0x%x). Max Phase shifts:%d\n", phase, phase, maxShift));
ALTERA_PLL_SetPhaseShift(phase, (int)ind, 0); ALTERA_PLL_SetPhaseShift(phase, (int)ind, 0);
clkPhase[ind] = val; clkPhase[ind] = valShift;
} }
int getPhase(enum CLKINDEX ind) { int getPhase(enum CLKINDEX ind, int degrees) {
return clkPhase[ind]; if (!degrees)
return clkPhase[ind];
return (clkPhase[ind] * (360.00 / (double)getMaxPhase(ind)));
}
int getMaxPhase(enum CLKINDEX ind) {
int ret = ((double)PLL_VCO_FREQ_MHZ / (double)clkDivider[ind]) * MAX_PHASE_SHIFTS_STEPS;
char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"};
FILE_LOG(logDEBUG1, ("Max Phase Shift (%s): %d (Clock: %d MHz, VCO:%d MHz)\n",
clock_names[ind], ret, clkDivider[ind], PLL_VCO_FREQ_MHZ));
return ret;
}
int validatePhaseinDegrees(enum speedVariable ind, int val, int retval) {
if (val == -1)
return OK;
enum CLKINDEX clkIndex;
switch(ind) {
case ADC_PHASE:
clkIndex = ADC_CLK;
break;
case DBIT_PHASE:
clkIndex = DBIT_CLK;
break;
default:
FILE_LOG(logERROR, ("Unknown speed enum %d for validating phase in degrees\n", (int)ind));
}
FILE_LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", clkIndex));
int maxShift = getMaxPhase(clkIndex);
// convert degrees to shift
double temp = val;
temp *= ((double)maxShift / 360.00);
if ((temp - (int)temp) > 0.0001) {
temp += 0.5;
}
val = (int)temp;
// convert back to degrees
val *= (360.00 / (double)maxShift);
if (val == retval)
return OK;
return FAIL;
} }
void configureFrequency(enum CLKINDEX ind, int val) { void configureFrequency(enum CLKINDEX ind, int val) {

View File

@ -1209,16 +1209,19 @@ int Beb_SetDetectorPosition(int pos[]) {
value &= UDP_HEADER_ID_MSK; // to keep previous id value value &= UDP_HEADER_ID_MSK; // to keep previous id value
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)); Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) if ((value & UDP_HEADER_X_MSK) != ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for left port\n"));
ret = FAIL; ret = FAIL;
}
// x right // x right
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_ID_MSK; // to keep previous id value value &= UDP_HEADER_ID_MSK; // to keep previous id value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)); Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) if ((value & UDP_HEADER_X_MSK) != ((pos[0] << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for right port\n"));
ret = FAIL; ret = FAIL;
}
@ -1228,8 +1231,10 @@ int Beb_SetDetectorPosition(int pos[]) {
value &= UDP_HEADER_Z_MSK; // to keep previous z value value &= UDP_HEADER_Z_MSK; // to keep previous z value
Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)); Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST);
if ((value & UDP_HEADER_Z_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for left port\n"));
ret = FAIL; ret = FAIL;
}
// y right // y right
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
@ -1237,8 +1242,10 @@ int Beb_SetDetectorPosition(int pos[]) {
posval = Beb_swap_uint16(Beb_top ? (pos[1]+1) : pos[1]); posval = Beb_swap_uint16(Beb_top ? (pos[1]+1) : pos[1]);
Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)); Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST); value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
if ((value & UDP_HEADER_Z_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for right port\n"));
ret = FAIL; ret = FAIL;
}
//close file pointer //close file pointer

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: cd5aea895b07b7af25e3fb74a341a861f9aa291c Repsitory UUID: c7ad548e4c2026a826b9f269f32d9970ce0a44e8
Revision: 30 Revision: 31
Branch: jungfrau Branch: refactor
Last Changed Author: Dhanya_Thattil Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4473 Last Changed Rev: 4478
Last Changed Date: 2019-03-22 17:13:44.000000002 +0100 ../slsDetectorServer/slsDetectorServer_funcs.c Last Changed Date: 2019-03-27 08:46:12.000000002 +0100 ./Beb.c

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "cd5aea895b07b7af25e3fb74a341a861f9aa291c" #define GITREPUUID "c7ad548e4c2026a826b9f269f32d9970ce0a44e8"
#define GITAUTH "Dhanya_Thattil" #define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4473 #define GITREV 0x4478
#define GITDATE 0x20190322 #define GITDATE 0x20190327
#define GITBRANCH "jungfrau" #define GITBRANCH "refactor"

View File

@ -820,6 +820,21 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret) {
return rois; return rois;
} }
// parameters - readout
void setSpeed(enum speedVariable ind, int val) {
switch(ind) {
case ADC_PHASE:
setPhaseShift(val);
break;
default:
return;
}
}
int getSpeed(enum speedVariable ind) {
// cannot get phase shift
return -1;
}
/* parameters - timer */ /* parameters - timer */

View File

@ -533,17 +533,6 @@
#define PATTERN_SET_LSB_REG (0x82 << MEM_MAP_SHIFT) #define PATTERN_SET_LSB_REG (0x82 << MEM_MAP_SHIFT)
#define PATTERN_SET_MSB_REG (0x83 << MEM_MAP_SHIFT) #define PATTERN_SET_MSB_REG (0x83 << MEM_MAP_SHIFT)
/** I2C Control register */
//#define I2C_TRANSFER_COMMAND_FIFO_REG (0x100 << MEM_MAP_SHIFT) // in FW, but not used anywhere
//#define I2C_CONTROL_REG (0x102 << MEM_MAP_SHIFT) // in FW, but not used anywhere
//#define I2C_RX_DATA_FIFO_LEVEL_REG (0x107 << MEM_MAP_SHIFT) // in FW, but not used anywhere
//#define I2C_SCL_LOW_COUNT_REG (0x108 << MEM_MAP_SHIFT) // in FW, but not used anywhere
//#define I2C_SCL_HIGH_COUNT_REG (0x109 << MEM_MAP_SHIFT) // in FW, but not used anywhere
//#define I2C_SDA_HOLD_REG (0x10A << MEM_MAP_SHIFT) // in FW, but not used anywhere

View File

@ -757,16 +757,15 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret) {
/* parameters - speed, readout */ /* parameters - speed, readout */
void setSpeed(enum speedVariable ind, int val) { void setSpeed(enum speedVariable ind, int val, int mode) {
switch(ind) { switch(ind) {
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT:
FILE_LOG(logINFOBLUE, ("Configuring ADC Phase\n")); FILE_LOG(logINFOBLUE, ("Configuring ADC Phase\n"));
configurePhase(ADC_CLK, val); configurePhase(ADC_CLK, val, mode);
break; break;
case DBIT_PHASE: case DBIT_PHASE:
FILE_LOG(logINFOBLUE, ("Configuring Dbit Phase\n")); FILE_LOG(logINFOBLUE, ("Configuring Dbit Phase\n"));
configurePhase(DBIT_CLK, val); configurePhase(DBIT_CLK, val, mode);
break; break;
case ADC_CLOCK: case ADC_CLOCK:
FILE_LOG(logINFOBLUE, ("Configuring ADC Clock\n")); FILE_LOG(logINFOBLUE, ("Configuring ADC Clock\n"));
@ -794,23 +793,26 @@ void setSpeed(enum speedVariable ind, int val) {
} }
} }
int getSpeed(enum speedVariable ind) { int getSpeed(enum speedVariable ind, int mode) {
switch(ind) { switch(ind) {
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT: return getPhase(ADC_CLK, mode);
return getPhase(ADC_CLK);
case DBIT_PHASE: case DBIT_PHASE:
return getPhase(DBIT_CLK); return getPhase(DBIT_CLK, mode);
case MAX_ADC_PHASE_SHIFT:
return getMaxPhase(ADC_CLK);
case MAX_DBIT_PHASE_SHIFT:
return getMaxPhase(DBIT_CLK);
case ADC_CLOCK: case ADC_CLOCK:
return getFrequency(ADC_CLK); return getFrequency(ADC_CLK);
case DBIT_CLOCK: case DBIT_CLOCK:
return getFrequency(DBIT_CLK); return getFrequency(DBIT_CLK);
case CLOCK_DIVIDER:
return getFrequency(RUN_CLK);
case ADC_PIPELINE: case ADC_PIPELINE:
return getAdcOffsetRegister(1); return getAdcOffsetRegister(1);
case DBIT_PIPELINE: case DBIT_PIPELINE:
return getAdcOffsetRegister(0); return getAdcOffsetRegister(0);
case CLOCK_DIVIDER:
return getFrequency(RUN_CLK);
default: default:
return -1; return -1;
} }
@ -1269,48 +1271,100 @@ int powerChip(int on) {
} }
// ind can only be ADC_CLK or DBIT_CLK // ind can only be ADC_CLK or DBIT_CLK
void configurePhase(enum CLKINDEX ind, int val) { void configurePhase(enum CLKINDEX ind, int val, int degrees) {
char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"}; char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"};
if (val > 65535 || val < -65535) { int maxShift = getMaxPhase(ind);
FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits\n", ind, clock_names[ind]));
return; // validation
} if (degrees && (val < 0 || val > 359)) {
int relativePhase = clkPhase[ind] - val; FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits (0 - 359°C)\n", ind, clock_names[ind]));
return;
}
if (!degrees && (val < 0 || val > maxShift - 1)) {
FILE_LOG(logERROR, ("\tPhase provided for C%d(%s) outside limits (0 - %d phase shifts)\n", ind, clock_names[ind], maxShift - 1));
return;
}
FILE_LOG(logINFO, ("Configuring Phase of C%d(%s) to %d (degree mode: %d)\n", ind, clock_names[ind], val, degrees));
int valShift = val;
// convert to phase shift
if (degrees) {
double temp = val * ((double)maxShift / 360.00);
if ((temp - (int)temp) > 0.0001) {
temp += 0.5;
}
valShift = temp;
FILE_LOG(logDEBUG1, ("phase shift: %d\n", valShift));
}
FILE_LOG(logDEBUG1, ("phase shift: %d (degrees/shift: %d)\n", valShift, val));
int relativePhase = clkPhase[ind] - valShift;
FILE_LOG(logDEBUG1, ("relative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
// same phase // same phase
if (!relativePhase) { if (!relativePhase) {
FILE_LOG(logDEBUG1, ("Nothing to do\n"));
return; return;
} }
FILE_LOG(logINFO, ("Configuring Phase of C%d(%s) to %d\n", ind, clock_names[ind], val));
// reset only pll
ALTERA_PLL_ResetPLL();
// set mode register to polling mode
ALTERA_PLL_SetModePolling();
int phase = 0; int phase = 0;
int maxShifts = (PLL_VCO_FREQ_MHZ / clkDivider[ind]) * MAX_PHASE_SHIFTS_STEPS;
FILE_LOG(logDEBUG1, ("Clock: %d MHz, VCO:%d MHz, Max Phase shifts:%d\n",
clkDivider[ind], PLL_VCO_FREQ_MHZ, maxShifts));
// delay clk
if (relativePhase > 0) { if (relativePhase > 0) {
phase = (maxShifts - relativePhase); phase = (maxShift - relativePhase);
} else { } else {
phase = (-1) * relativePhase; phase = (-1) * relativePhase;
} }
FILE_LOG(logINFO, ("\tphase out %d (0x%08x)\n", phase, phase)); FILE_LOG(logDEBUG1, ("[Single Direction] Phase:%d (0x%x). Max Phase shifts:%d\n", phase, phase, maxShift));
ALTERA_PLL_SetPhaseShift(phase, (int)ind, 0); ALTERA_PLL_SetPhaseShift(phase, (int)ind, 0);
clkPhase[ind] = val; clkPhase[ind] = valShift;
} }
int getPhase(enum CLKINDEX ind) { int getPhase(enum CLKINDEX ind, int degrees) {
return clkPhase[ind]; if (!degrees)
return clkPhase[ind];
return (clkPhase[ind] * (360.00 / (double)getMaxPhase(ind)));
}
int getMaxPhase(enum CLKINDEX ind) {
int ret = ((double)PLL_VCO_FREQ_MHZ / (double)clkDivider[ind]) * MAX_PHASE_SHIFTS_STEPS;
char clock_names[4][10]={"run_clk","adc_clk", "sync_clk", "dbit_clk"};
FILE_LOG(logDEBUG1, ("Max Phase Shift (%s): %d (Clock: %d MHz, VCO:%d MHz)\n",
clock_names[ind], ret, clkDivider[ind], PLL_VCO_FREQ_MHZ));
return ret;
}
int validatePhaseinDegrees(enum speedVariable ind, int val, int retval) {
if (val == -1)
return OK;
enum CLKINDEX clkIndex;
switch(ind) {
case ADC_PHASE:
clkIndex = ADC_CLK;
break;
case DBIT_PHASE:
clkIndex = DBIT_CLK;
break;
default:
FILE_LOG(logERROR, ("Unknown speed enum %d for validating phase in degrees\n", (int)ind));
}
FILE_LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", clkIndex));
int maxShift = getMaxPhase(clkIndex);
// convert degrees to shift
double temp = val;
temp *= ((double)maxShift / 360.00);
if ((temp - (int)temp) > 0.0001) {
temp += 0.5;
}
val = (int)temp;
// convert back to degrees
val *= (360.00 / (double)maxShift);
if (val == retval)
return OK;
return FAIL;
} }
void configureFrequency(enum CLKINDEX ind, int val) { void configureFrequency(enum CLKINDEX ind, int val) {
@ -1929,23 +1983,45 @@ void unsetFifoReadStrobes() {
void readSample(int ns) { void readSample(int ns) {
uint32_t addr = DUMMY_REG; uint32_t addr = DUMMY_REG;
// read analog data
uint32_t fifoAddr = FIFO_DATA_REG;
// read digital output // read strobe to all analog fifos
// read strobe to digital fifo bus_w(addr, bus_r(addr) | DUMMY_ANLG_FIFO_RD_STRBE_MSK);
bus_w(addr, bus_r(addr) | DUMMY_DGTL_FIFO_RD_STRBE_MSK); bus_w(addr, bus_r(addr) & (~DUMMY_ANLG_FIFO_RD_STRBE_MSK));
bus_w(addr, bus_r(addr) & (~DUMMY_DGTL_FIFO_RD_STRBE_MSK)); // wait as it is connected directly to fifo running on a different clock
// wait as it is connected directly to fifo running on a different clock //usleep(WAIT_TIME_FIFO_RD_STROBE);
if (!(ns%1000)) { if (!(ns%1000)) {
FILE_LOG(logDEBUG1, ("Reading sample ns:%d of %d DEmtpy:%d DFull:%d Status:0x%x\n", FILE_LOG(logDEBUG1, ("Reading sample ns:%d of %d AEmtpy:0x%x AFull:0x%x Status:0x%x\n",
ns, nSamples, ns, nSamples, bus_r(FIFO_EMPTY_REG), bus_r(FIFO_FULL_REG), bus_r(STATUS_REG)));
((bus_r(FIFO_DIN_STATUS_REG) & FIFO_DIN_STATUS_FIFO_EMPTY_MSK) >> FIFO_DIN_STATUS_FIFO_EMPTY_OFST), }
((bus_r(FIFO_DIN_STATUS_REG) & FIFO_DIN_STATUS_FIFO_FULL_MSK) >> FIFO_DIN_STATUS_FIFO_FULL_OFST),
bus_r(STATUS_REG)));
}
// read fifo and write it to current position of data pointer // loop through all channels
*((uint64_t*)now_ptr) = get64BitReg(FIFO_DIN_LSB_REG, FIFO_DIN_MSB_REG); int ich = 0;
now_ptr += 8; for (ich = 0; ich < NCHAN_ANALOG; ++ich) {
// if channel is in ROI
if ((1 << ich) & ~(adcDisableMask)) {
// unselect channel
bus_w(addr, bus_r(addr) & ~(DUMMY_FIFO_CHNNL_SLCT_MSK));
// select channel
bus_w(addr, bus_r(addr) | ((ich << DUMMY_FIFO_CHNNL_SLCT_OFST) & DUMMY_FIFO_CHNNL_SLCT_MSK));
// read fifo and write it to current position of data pointer
*((uint16_t*)now_ptr) = bus_r16(fifoAddr);
// keep reading till the value is the same
/* while (*((uint16_t*)now_ptr) != bus_r16(fifoAddr)) {
FILE_LOG(logDEBUG1, ("%d ", ich));
*((uint16_t*)now_ptr) = bus_r16(fifoAddr);
}*/
// increment pointer to data out destination
now_ptr += 2;
}
}
} }

View File

@ -207,7 +207,7 @@ int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
uint32_t low_count = total_div / 2; uint32_t low_count = total_div / 2;
uint32_t high_count = low_count; uint32_t high_count = low_count;
uint32_t odd_division = 0; uint32_t odd_division = 0;
cprintf(RED, "toatldiv:%f\n", total_div);
// odd division // odd division
if (total_div > (float)(2 * low_count)) { if (total_div > (float)(2 * low_count)) {
++high_count; ++high_count;

View File

@ -115,7 +115,10 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret);
#endif #endif
// parameters - readout // parameters - readout
#ifndef GOTTHARDD #if defined(CHIPTESTBOARDD) || defined(MOENCHD)
void setSpeed(enum speedVariable ind, int val, int mode);
int getSpeed(enum speedVariable ind, int mode);
#else
void setSpeed(enum speedVariable ind, int val); void setSpeed(enum speedVariable ind, int val);
int getSpeed(enum speedVariable ind); int getSpeed(enum speedVariable ind);
#endif #endif
@ -238,8 +241,10 @@ int powerChip (int on);
// chip test board or moench specific - configure frequency, phase, pll, flashing firmware // chip test board or moench specific - configure frequency, phase, pll, flashing firmware
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) #if defined(CHIPTESTBOARDD) || defined(MOENCHD)
void configurePhase(enum CLKINDEX ind, int val); void configurePhase(enum CLKINDEX ind, int val, int degrees);
int getPhase(enum CLKINDEX ind); int getPhase(enum CLKINDEX ind, int degrees);
int getMaxPhase(enum CLKINDEX ind);
int validatePhaseinDegrees(enum speedVariable ind, int val, int retval);
void configureFrequency(enum CLKINDEX ind, int val); void configureFrequency(enum CLKINDEX ind, int val);
int getFrequency(enum CLKINDEX ind); int getFrequency(enum CLKINDEX ind);
void configureSyncFrequency(enum CLKINDEX ind); void configureSyncFrequency(enum CLKINDEX ind);

View File

@ -140,14 +140,14 @@ const char* getTimerName(enum timerIndex ind) {
const char* getSpeedName(enum speedVariable ind) { const char* getSpeedName(enum speedVariable ind) {
switch (ind) { switch (ind) {
case CLOCK_DIVIDER: return "clock_divider"; case CLOCK_DIVIDER: return "clock_divider";
case PHASE_SHIFT: return "phase_shift";
case OVERSAMPLING: return "oversampling";
case ADC_CLOCK: return "adc_clock"; case ADC_CLOCK: return "adc_clock";
case ADC_PHASE: return "adc_phase"; case ADC_PHASE: return "adc_phase";
case ADC_PIPELINE: return "adc_pipeline"; case ADC_PIPELINE: return "adc_pipeline";
case DBIT_CLOCK: return "dbit_clock"; case DBIT_CLOCK: return "dbit_clock";
case DBIT_PHASE: return "dbit_phase"; case DBIT_PHASE: return "dbit_phase";
case DBIT_PIPELINE: return "dbit_pipeline"; case DBIT_PIPELINE: return "dbit_pipeline";
case MAX_ADC_PHASE_SHIFT: return "max_adc_phase_shift";
case MAX_DBIT_PHASE_SHIFT: return "max_dbit_phase_shift";
default: return "unknown_speed"; default: return "unknown_speed";
} }
} }
@ -1938,74 +1938,98 @@ int set_roi(int file_des) {
int set_speed(int file_des) { int set_speed(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int args[2] = {-1,-1}; int args[3] = {-1, -1, -1};
int retval = -1; int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0) if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
#ifdef GOTTHARDD
functionNotImplemented();
#else
enum speedVariable ind = args[0]; enum speedVariable ind = args[0];
int val = args[1]; int val = args[1];
int GET_VAL = -1; int mode = args[2];
if ((ind == PHASE_SHIFT) || (ind == ADC_PHASE) || (ind == DBIT_PHASE))
GET_VAL = 100000;
char speedName[20] = {0}; char speedName[20] = {0};
strcpy(speedName, getSpeedName(ind)); strcpy(speedName, getSpeedName(ind));
FILE_LOG(logDEBUG1, ("Setting speed index %s (%d) to %d\n", speedName, ind, val)); FILE_LOG(logDEBUG1, ("Setting speed index %s (speedVariable %d) to %d (mode: %d)\n", speedName, ind, val, mode));
// check index // check index
switch(ind) { switch(ind) {
#ifdef JUNGFRAUD #ifdef JUNGFRAUD
case ADC_PHASE: case ADC_PHASE:
case CLOCK_DIVIDER:
#elif CHIPTESTBOARDD #elif CHIPTESTBOARDD
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT:
case DBIT_PHASE: case DBIT_PHASE:
case MAX_ADC_PHASE_SHIFT:
case MAX_DBIT_PHASE_SHIFT:
case ADC_CLOCK: case ADC_CLOCK:
case DBIT_CLOCK: case DBIT_CLOCK:
case CLOCK_DIVIDER:
case ADC_PIPELINE: case ADC_PIPELINE:
case DBIT_PIPELINE: case DBIT_PIPELINE:
#elif MOENCHD #elif MOENCHD
case ADC_PHASE: case ADC_PHASE:
case PHASE_SHIFT:
case DBIT_PHASE: case DBIT_PHASE:
case MAX_ADC_PHASE_SHIFT:
case MAX_DBIT_PHASE_SHIFT:
case ADC_CLOCK: case ADC_CLOCK:
case DBIT_CLOCK: case DBIT_CLOCK:
case CLOCK_DIVIDER:
case ADC_PIPELINE: case ADC_PIPELINE:
case DBIT_PIPELINE: case DBIT_PIPELINE:
#endif #elif GOTTHARDD
case ADC_PHASE:
#elif EIGERD
case CLOCK_DIVIDER: case CLOCK_DIVIDER:
#endif
break; break;
default: default:
modeNotImplemented(speedName, (int)ind); modeNotImplemented(speedName, (int)ind);
break; break;
} }
#if (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD))
if (ret == OK) { if (ret == OK && mode == 1) {
// set ret = FAIL;
if ((val != GET_VAL) && (Server_VerifyLock() == OK)) { strcpy(mess, "deg is not defined for this detector.\n");
setSpeed(ind, val); FILE_LOG(logERROR,(mess));
}
// get
retval = getSpeed(ind);
FILE_LOG(logDEBUG1, ("%s: %d\n", speedName, retval));
// validate
if (GET_VAL == -1) {
char validateName[20] = {0};
sprintf(validateName, "set %s", speedName);
validate(val, retval, validateName, DEC);
} else if (ret == OK && val != GET_VAL && retval != val ) {
ret = FAIL;
sprintf(mess, "Could not set %s. Set %d, but read %d\n", speedName, val, retval);
FILE_LOG(logERROR,(mess));
}
} }
#endif #endif
if (ret == OK) {
// set
if ((val != -1) && (Server_VerifyLock() == OK)) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
setSpeed(ind, val, mode);
#else
setSpeed(ind, val);
#endif
}
// get
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
retval = getSpeed(ind, mode);
#else
retval = getSpeed(ind);
#endif
FILE_LOG(logDEBUG1, ("%s: %d (mode:%d)\n", speedName, retval, mode));
// validate
char validateName[20] = {0};
sprintf(validateName, "set %s", speedName);
#ifndef GOTTHARDD
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
if (ind == ADC_PHASE || ind == DBIT_PHASE && mode == 1) {
ret = validatePhaseinDegrees(ind, val, retval);
if (ret == FAIL) {
sprintf(mess, "Could not set %s. Set %s, got %s\n", validateName);
FILE_LOG(logERROR,(mess));
}
} else
validate(val, retval, validateName, DEC);
#else
validate(val, retval, validateName, DEC);
#endif
#endif
}
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
} }

View File

@ -734,14 +734,14 @@ class multiSlsDetector : public virtual slsDetectorDefs {
/** /**
* Set speed * Set speed
* @param sp speed type (clkdivider option for Jungfrau and Eiger, others * @param sp speed type (clkdivider option for Jungfrau and Eiger,
* for Mythen/Gotthard) * adcphase for Gotthard, others for CTB & Moench)
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other * @param value (clkdivider 0,1,2 for full, half and quarter speed). Other
* values check manual * values check manual
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns value of speed set * @returns value of speed set
*/ */
int setSpeed(speedVariable index, int value = -1, int detPos = -1); int setSpeed(speedVariable index, int value = -1, int mode = 0, int detPos = -1);
/** /**
* Set/get dynamic range and updates the number of dataBytes * Set/get dynamic range and updates the number of dataBytes

View File

@ -697,11 +697,12 @@ class slsDetector : public virtual slsDetectorDefs{
/** /**
* Set speed * Set speed
* @param sp speed type (clkdivider option for Jungfrau and Eiger, others for Mythen/Gotthard) * @param sp speed type (clkdivider option for Jungfrau and Eiger,
* adcphase for Gotthard, others for CTB & Moench)
* @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual * @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual
* @returns value of speed set * @returns value of speed set
*/ */
int setSpeed(speedVariable sp, int value = -1); int setSpeed(speedVariable sp, int value = -1, int mode = 0);
/** /**
* Set/get dynamic range and updates the number of dataBytes * Set/get dynamic range and updates the number of dataBytes

View File

@ -1199,14 +1199,14 @@ int64_t multiSlsDetector::getTimeLeft(timerIndex index, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::setSpeed(speedVariable index, int value, int detPos) { int multiSlsDetector::setSpeed(speedVariable index, int value, int mode, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setSpeed(index, value); return detectors[detPos]->setSpeed(index, value, mode);
} }
// multi // multi
auto r = parallelCall(&slsDetector::setSpeed, index, value); auto r = parallelCall(&slsDetector::setSpeed, index, value, mode);
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }

View File

@ -1840,12 +1840,12 @@ int64_t slsDetector::getTimeLeft(timerIndex index) {
return retval; return retval;
} }
int slsDetector::setSpeed(speedVariable sp, int value) { int slsDetector::setSpeed(speedVariable sp, int value, int mode) {
int fnum = F_SET_SPEED; int fnum = F_SET_SPEED;
int ret = FAIL; int ret = FAIL;
int args[2] = {(int)sp, value}; int args[3] = {(int)sp, value, mode};
int retval = -1; int retval = -1;
FILE_LOG(logDEBUG1) << "Setting speed index " << sp << " to " << value; FILE_LOG(logDEBUG1) << "Setting speed index " << sp << " to " << value << " mode: " << mode;
if (detector_shm()->onlineFlag == ONLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);

File diff suppressed because it is too large Load Diff

View File

@ -722,8 +722,10 @@ int slsReceiverImplementation::setUDPSocketBufferSize(const int64_t s) {
int64_t size = (s == 0) ? udpSocketBufferSize : s; int64_t size = (s == 0) ? udpSocketBufferSize : s;
size_t listSize = listener.size(); size_t listSize = listener.size();
if ((int)listSize != numUDPInterfaces) if (myDetectorType == JUNGFRAU && (int)listSize != numUDPInterfaces) {
FILE_LOG(logERROR) << "Number of Interfaces " << numUDPInterfaces << " do not match listener size " << listSize;
return FAIL; return FAIL;
}
for (unsigned int i = 0; i < listSize; ++i) { for (unsigned int i = 0; i < listSize; ++i) {
if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL) if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL)

View File

@ -733,13 +733,16 @@ int slsReceiverTCPIPInterface::setup_udp(){
uint32_t port2 = atoi(args[5]); uint32_t port2 = atoi(args[5]);
// using the 2nd interface only // using the 2nd interface only
if (numInterfaces == 1 && selInterface == 2) { if (myDetectorType == JUNGFRAU && numInterfaces == 1 && selInterface == 2) {
ip1 = ip2; ip1 = ip2;
port1 = port2; port1 = port2;
} }
// 1st interface // 1st interface
receiver->setUDPPortNumber(port1); receiver->setUDPPortNumber(port1);
if (myDetectorType == EIGER) {
receiver->setUDPPortNumber2(port2);
}
FILE_LOG(logINFO) << "Receiver UDP IP: " << ip1; FILE_LOG(logINFO) << "Receiver UDP IP: " << ip1;
// get eth // get eth
std::string temp = genericSocket::ipToName(ip1); std::string temp = genericSocket::ipToName(ip1);
@ -769,7 +772,7 @@ int slsReceiverTCPIPInterface::setup_udp(){
FILE_LOG(logERROR) << mess; FILE_LOG(logERROR) << mess;
} else { } else {
// using the 2nd interface only // using the 2nd interface only
if (numInterfaces == 1 && selInterface == 2) { if (myDetectorType == JUNGFRAU && numInterfaces == 1 && selInterface == 2) {
strcpy(retvals[1],temp.c_str()); strcpy(retvals[1],temp.c_str());
FILE_LOG(logINFO) << "Receiver MAC Address: " << retvals[1]; FILE_LOG(logINFO) << "Receiver MAC Address: " << retvals[1];
} }
@ -782,7 +785,7 @@ int slsReceiverTCPIPInterface::setup_udp(){
} }
// 2nd interface // 2nd interface
if (numInterfaces == 2) { if (myDetectorType == JUNGFRAU && numInterfaces == 2) {
receiver->setUDPPortNumber2(port2); receiver->setUDPPortNumber2(port2);
FILE_LOG(logINFO) << "Receiver UDP IP 2: " << ip2; FILE_LOG(logINFO) << "Receiver UDP IP 2: " << ip2;
// get eth // get eth
@ -820,7 +823,7 @@ int slsReceiverTCPIPInterface::setup_udp(){
} }
// set the number of udp interfaces (changes number of threads and many others) // set the number of udp interfaces (changes number of threads and many others)
if (receiver->setNumberofUDPInterfaces(numInterfaces) == FAIL) { if (myDetectorType == JUNGFRAU && receiver->setNumberofUDPInterfaces(numInterfaces) == FAIL) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Failed to set number of interfaces\n"); sprintf(mess, "Failed to set number of interfaces\n");
FILE_LOG(logERROR) << mess; FILE_LOG(logERROR) << mess;

View File

@ -502,14 +502,14 @@ public:
*/ */
enum speedVariable { enum speedVariable {
CLOCK_DIVIDER, /**< readout clock divider */ CLOCK_DIVIDER, /**< readout clock divider */
PHASE_SHIFT, /**< adds phase shift */
OVERSAMPLING, /**< oversampling for analog detectors */
ADC_CLOCK, /**< adc clock divider */ ADC_CLOCK, /**< adc clock divider */
ADC_PHASE, /**< adc clock phase */ ADC_PHASE, /**< adc clock phase */
ADC_PIPELINE, /**< adc pipeline */ ADC_PIPELINE, /**< adc pipeline */
DBIT_CLOCK, /**< adc clock divider */ DBIT_CLOCK, /**< adc clock divider */
DBIT_PHASE, /**< adc clock phase */ DBIT_PHASE, /**< adc clock phase */
DBIT_PIPELINE /**< adc pipeline */ DBIT_PIPELINE, /**< adc pipeline */
MAX_ADC_PHASE_SHIFT, /** max adc phase shift */
MAX_DBIT_PHASE_SHIFT, /** max adc phase shift */
}; };