mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-15 05:18:41 +01:00
ctb: add patternstart command, xilinx: fix frequency (#1307)
* add patternstart command for CTB, block end of execution udp packets if pattern was started by patternstart command * update docs * Dhanya's comments * more Dhanya comments * refactored * fixed tests for startpatttern, also clkfrequency not properly used in server * xilinx: fixed setfrequency, tick clock (with sync clock), clkfrequency set from getfrequency to get the exact value * xilinx freq in kHz, updated default values and prints --------- Co-authored-by: Martin Mueller <martin.mueller@psi.ch> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
Binary file not shown.
@@ -40,8 +40,7 @@ char initErrorMessage[MAX_STR_LENGTH];
|
||||
|
||||
int detPos[2] = {0, 0};
|
||||
|
||||
uint32_t clkFrequency[NUM_CLOCKS] = {20, 100, 20, 100};
|
||||
|
||||
uint32_t clkFrequency[NUM_CLOCKS] = {};
|
||||
int chipConfigured = 0;
|
||||
int analogEnable = 0;
|
||||
int digitalEnable = 0;
|
||||
@@ -376,6 +375,10 @@ void setupDetector() {
|
||||
LOG(logINFO, ("Setting up Server for 1 Xilinx Chip Test Board\n"));
|
||||
|
||||
// default variables
|
||||
clkFrequency[RUN_CLK] = DEFAULT_RUN_CLK;
|
||||
clkFrequency[ADC_CLK] = DEFAULT_ADC_CLK;
|
||||
clkFrequency[SYNC_CLK] = DEFAULT_SYNC_CLK;
|
||||
clkFrequency[DBIT_CLK] = DEFAULT_DBIT_CLK;
|
||||
chipConfigured = 0;
|
||||
analogEnable = 0;
|
||||
digitalEnable = 0;
|
||||
@@ -1061,12 +1064,12 @@ int setPeriod(int64_t val) {
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
|
||||
val *= (1E-3 * RUN_CLK);
|
||||
val *= (1E-3 * clkFrequency[RUN_CLK]);
|
||||
setU64BitReg(val, PERIOD_IN_REG_1, PERIOD_IN_REG_2);
|
||||
|
||||
// validate for tolerance
|
||||
int64_t retval = getPeriod();
|
||||
val /= (1E-3 * RUN_CLK);
|
||||
val /= (1E-3 * clkFrequency[RUN_CLK]);
|
||||
if (val != retval) {
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1074,7 +1077,8 @@ int setPeriod(int64_t val) {
|
||||
}
|
||||
|
||||
int64_t getPeriod() {
|
||||
return getU64BitReg(PERIOD_IN_REG_1, PERIOD_IN_REG_2) / (1E-3 * RUN_CLK);
|
||||
return getU64BitReg(PERIOD_IN_REG_1, PERIOD_IN_REG_2) /
|
||||
(1E-3 * clkFrequency[RUN_CLK]);
|
||||
}
|
||||
|
||||
int setDelayAfterTrigger(int64_t val) {
|
||||
@@ -1083,12 +1087,12 @@ int setDelayAfterTrigger(int64_t val) {
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("Setting delay after trigger %ld ns\n", val));
|
||||
val *= (1E-3 * RUN_CLK);
|
||||
val *= (1E-3 * clkFrequency[RUN_CLK]);
|
||||
setU64BitReg(val, DELAY_IN_REG_1, DELAY_IN_REG_2);
|
||||
|
||||
// validate for tolerance
|
||||
int64_t retval = getDelayAfterTrigger();
|
||||
val /= (1E-3 * RUN_CLK);
|
||||
val /= (1E-3 * clkFrequency[RUN_CLK]);
|
||||
if (val != retval) {
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1096,7 +1100,8 @@ int setDelayAfterTrigger(int64_t val) {
|
||||
}
|
||||
|
||||
int64_t getDelayAfterTrigger() {
|
||||
return getU64BitReg(DELAY_IN_REG_1, DELAY_IN_REG_2) / (1E-3 * RUN_CLK);
|
||||
return getU64BitReg(DELAY_IN_REG_1, DELAY_IN_REG_2) /
|
||||
(1E-3 * clkFrequency[RUN_CLK]);
|
||||
}
|
||||
|
||||
int64_t getNumFramesLeft() {
|
||||
@@ -1108,11 +1113,13 @@ int64_t getNumTriggersLeft() {
|
||||
}
|
||||
|
||||
int64_t getDelayAfterTriggerLeft() {
|
||||
return getU64BitReg(DELAY_OUT_REG_1, DELAY_OUT_REG_2) / (1E-3 * RUN_CLK);
|
||||
return getU64BitReg(DELAY_OUT_REG_1, DELAY_OUT_REG_2) /
|
||||
(1E-3 * clkFrequency[RUN_CLK]);
|
||||
}
|
||||
|
||||
int64_t getPeriodLeft() {
|
||||
return getU64BitReg(PERIOD_OUT_REG_1, PERIOD_OUT_REG_2) / (1E-3 * RUN_CLK);
|
||||
return getU64BitReg(PERIOD_OUT_REG_1, PERIOD_OUT_REG_2) /
|
||||
(1E-3 * clkFrequency[RUN_CLK]);
|
||||
}
|
||||
|
||||
int64_t getFramesFromStart() {
|
||||
@@ -1122,12 +1129,12 @@ int64_t getFramesFromStart() {
|
||||
|
||||
int64_t getActualTime() {
|
||||
return getU64BitReg(TIME_FROM_START_OUT_REG_1, TIME_FROM_START_OUT_REG_2) /
|
||||
(1E-3 * TICK_CLK);
|
||||
(1E-3 * clkFrequency[SYNC_CLK]);
|
||||
}
|
||||
|
||||
int64_t getMeasurementTime() {
|
||||
return getU64BitReg(FRAME_TIME_OUT_REG_1, FRAME_TIME_OUT_REG_2) /
|
||||
(1E-3 * TICK_CLK);
|
||||
(1E-3 * clkFrequency[SYNC_CLK]);
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
@@ -1792,10 +1799,16 @@ int setFrequency(enum CLKINDEX ind, int val) {
|
||||
}
|
||||
|
||||
char *clock_names[] = {CLK_NAMES};
|
||||
LOG(logINFO, ("\tSetting %s clock (%d) frequency to %d MHz\n",
|
||||
LOG(logINFO, ("\tSetting %s clock (%d) frequency to %d kHz\n",
|
||||
clock_names[ind], ind, val));
|
||||
|
||||
XILINX_PLL_setFrequency(ind, val);
|
||||
if (XILINX_PLL_setFrequency(ind, val) == FAIL) {
|
||||
LOG(logERROR, ("\tCould not set %s clock (%d) frequency to %d kHz\n",
|
||||
clock_names[ind], ind, val));
|
||||
return FAIL;
|
||||
}
|
||||
clkFrequency[ind] = val;
|
||||
// TODO later: connect setPhase as phase gets reset on freq change
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1804,5 +1817,8 @@ int getFrequency(enum CLKINDEX ind) {
|
||||
LOG(logERROR, ("Unknown clock index %d to get frequency\n", ind));
|
||||
return -1;
|
||||
}
|
||||
return XILINX_PLL_getFrequency(ind);
|
||||
#ifndef VIRTUAL
|
||||
clkFrequency[ind] = XILINX_PLL_getFrequency(ind);
|
||||
#endif
|
||||
return clkFrequency[ind];
|
||||
}
|
||||
@@ -71,8 +71,6 @@
|
||||
#define POWER_RGLTR_MAX (2661)
|
||||
#define VIO_MIN_MV (1200) // for fpga to function
|
||||
|
||||
#define TICK_CLK (20) // MHz (trig_timeFromStart, frametime, timeFromStart)
|
||||
|
||||
/* Defines in the Firmware */
|
||||
#define WAIT_TIME_PATTERN_READ (10)
|
||||
#define WAIT_TIME_OUT_0US_TIMES (35000) // 2s
|
||||
@@ -156,4 +154,9 @@ typedef struct udp_header_struct {
|
||||
#define UDP_IP_HEADER_LENGTH_BYTES (28)
|
||||
|
||||
enum CLKINDEX { RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS };
|
||||
#define CLK_NAMES "run", "adc", "sync", "dbit"
|
||||
#define CLK_NAMES "run", "adc", "sync", "dbit"
|
||||
|
||||
#define DEFAULT_RUN_CLK (20000) // 20 MHz
|
||||
#define DEFAULT_ADC_CLK (100000) // 100 MHz
|
||||
#define DEFAULT_SYNC_CLK (20000) // 20 MHz
|
||||
#define DEFAULT_DBIT_CLK (100000) // 100 MHz
|
||||
Reference in New Issue
Block a user